Ive only just started using classes in python and so cant figure out how to fix this presumably simple error. I have a class that essentially collates multiple csv files, sorts and cleans the data, and outputs a finished list, looks like below:
class CollateCSV():
def __init__(self, input_dir="", file_list="", output=False):
# initialises some global variables
def read_file_list(self):
#reads a csv file of already "dealt with" files
return x #list of filenames
def list_files_to_read(self, show=False, perm=True):
#gives list of csv files yet to be cleaned - the ones the program will actually import and read
return files_to_read
def sort_list(self, unsorted_list):
#sorts a list of OrderedDict by multiple keys
return sorted_list
def import_sort(self):
#reads each CSV file, cleans it, passes it to sort_list function and returns cleaned & sorted list of OrderedDict
return sort_list(x)
def return_final_list(self):
#does some things relating to logging if self.output == True. But used mainly as single easy place to return the final sorted & cleaned list of OrderedDict
return import_sort()
The way I have setup my project, this code is in a seperate file to my main code, and so Ive imported this as a module. As such I know the code itself works as when running the below code Ive got errors that Ive fixed indicating missing variables or syntax errors etc throughout the above code.
from convert import CollateCSV
x = CollateCSV("./csv_files", "./file_list.csv", output=False)
print(x.list_files_to_reas())
The problem I have is when I run the above code know I get an eror saying:
for file in list_files_to_read(show=False, perm=True):
NameError: name 'list_files_to_read' is not defined
Ive tried moving the functions within the CollateCSV class around, and attempted to do the second piece of code in the same file as the first, but still get the same error. Could someone impart some advice on what Im doing wrong with classes in python? Thanks.