Python Forum
how to run another function from main file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to run another function from main file
#3
Your csv is wrong formated, delimiter should be tab(you have 3 spaces or 4 four spaces)

my.csv

C1	C2	C3
A	20	2020/05/03 20:45:12
B	5	2020/06/23 10:45:12
main.py

import logging
from datetime import datetime
import pandas as pd
from read_data import data
import sys

working_dir = sys.argv[0].rpartition("/")[0]

def main():
    if __name__ == '__main__':
        data.read_data(f'{working_dir}/my.csv', colNames ='col1', mode = 'NOM', delimiter = "\t")
        
main()
read_data.py

import pandas as pd
import logging
import sys

working_dir = sys.argv[0].rpartition("/")[0]

class MyData:  
    def __init__(self):  
        self.mode = None
         
        
    def read_data(self, inFile, colNames, mode, delimiter):
        self.infile = inFile
        print("The infile name",inFile)       
        try:
            self.df = pd.read_csv(inFile, delimiter = "\t")
            print(self.df.head(2))
            self.df.to_csv(f"{working_dir}/final.csv",index=False, sep = "\t")
            logging.debug("Read data successfully")
        except OSError as e:
            logging.debug("File read fail check fail reason below")
            logging.debug(e.errno)
        
 
data = MyData()
Reply


Messages In This Thread
RE: how to run another function from main file - by Axel_Erfurt - Aug-08-2020, 12:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,161 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  python run all py files from main py file mg24 6 1,448 Oct-12-2022, 04:41 AM
Last Post: mg24
  Function global not readable by 'main' fmr300 1 1,391 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  Problem with user defined main menu function stefzeer 3 2,451 Mar-27-2020, 06:12 AM
Last Post: buran
  main def function puertas12 1 1,946 Jun-11-2019, 11:39 AM
Last Post: snippsat
  Print out the tuple from the function main whatloop 2 2,432 Mar-25-2019, 10:27 AM
Last Post: whatloop
  Use Variables Generated from Functions in different files to use on the main file AykutRobotics 3 3,003 Jan-01-2019, 04:19 PM
Last Post: AykutRobotics
  main function scope issues wak_stephanie 1 2,501 Aug-29-2018, 02:53 AM
Last Post: Larz60+
  I'm having trouble printing a return value in my main function RedSkeleton007 2 3,150 Apr-08-2018, 04:17 PM
Last Post: IAMK
  Cannot call main function but I don't know why eml 2 2,822 Mar-09-2018, 12:14 PM
Last Post: eml

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020