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
#1
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

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
Reply


Messages In This Thread
how to run another function from main file - by Mekala - Aug-08-2020, 10:13 AM

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,162 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  python run all py files from main py file mg24 6 1,449 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