Sep-09-2019, 04:28 PM
Hi,
I defined two function in a forloop, and on each iteration both function should trigger. I use below code, and I am not getting any output.
NameError: name 'f' is not defined
may be my function definition or function calling is bad.
I defined two function in a forloop, and on each iteration both function should trigger. I use below code, and I am not getting any output.
import pandas as pd input=open(r'D:\PythonCodes\InputCSV.csv','r') output=open(r'D:\PythonCodes\OutCSV.csv','w',newline="") lst_file_smry=['InputCSV','InputCSV2'] in_dir='D:\\Mekala_Backupdata\PythonCodes' out_dir='D:\\Mekala_Backupdata\PythonCodes' file_name=in_dir+"\\"+lst_file_smry[1] len_file_lst=len(lst_file_smry) for i in range(len(lst_file_smry)): input_file= in_dir+"\\"+lst_file_smry[i]+".csv" output_file=out_dir+"\\"+lst_file_smry[i]+"out.csv" print("infile:",input_file) print("outfile:",output_file) def readxl(): f= pd.read_csv(input_file) if __name__== "__main__": readxl() def write2csv(): f.to_csv(output_file) if __name__== "__main__": write2csv()error:
NameError: name 'f' is not defined
may be my function definition or function calling is bad.