Aug-08-2020, 10:13 AM
Hi,
I have main.py & read_data.py and ready csv file and write. I want to call read_data.py and execute. Byt it giving error as below.
NameError: name 'inFile' is not defined
[/python]
main.py
I have main.py & read_data.py and ready csv file and write. I want to call read_data.py and execute. Byt it giving error as below.
NameError: name 'inFile' is not defined
[/python]
main.py
import logging from datetime import datetime import pandas as pd from read_data import data def main(): if __name__ == '__main__': data.read_data(inFile= 'my.csv', colNames ='col1', mode = 'NOM')read_data.py:
import pandas as pd import logging class MyData: def __init__(self): self.mode = None def read_data(self, inFile, colNames, mode): self.infile = inFile print("The infile name",inFile) try: self.df = pd.read_csv(inFile) print(self.df.head(2)) self.df.to_csv("final.csv",index=False) logging.debug("Read data successfully") except OSError as e: logging.debug("File read fail check fail reason below") logging.debug(e.errno) data = MyData() data.read_data(inFile, colNames, mode)my.csv:
C1 C2 C3 A 20 2020/05/03 20:45:12 B 5 2020/06/23 10:45:12