why it showed that the argument of my function was not defined? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: why it showed that the argument of my function was not defined? (/thread-10263.html) |
why it showed that the argument of my function was not defined? - Tony - May-17-2018 here is my codes,I wrote a function which should be able to read a csv file and parse it into some useful form. import csv def load_atlas(filename): edited_file = [] with open('filename', 'r') as csv_file: csv_reader = csv.reader(csv_file, delimiter='|') for lines in csv_reader: edited_file.append(lines) return edited_file load_atlas(ala-acton.txt)my problem is whenever i passed a filename into this function, it returns an error
RE: why it showed that the argument of my function was not defined? - Larz60+ - May-17-2018 place it in quotes: load_atlas('ala-acton.txt') RE: why it showed that the argument of my function was not defined? - Tony - May-17-2018 (May-17-2018, 05:55 AM)Larz60+ Wrote: place it in quotes:Thank you for your help.When i place in the quotes the program is going to open a file called "filename" which does not exist here is the error message may I ask do we have a method to modify it?(May-17-2018, 05:54 AM)Tony Wrote: #3I got it!!!again,Thank you for you help,I was confused by this for a while. RE: why it showed that the argument of my function was not defined? - Larz60+ - May-17-2018 you need to find the file. RE: why it showed that the argument of my function was not defined? - buran - May-17-2018 import csv def load_atlas(filename): edited_file = [] with open(filename, 'r') as csv_file: csv_reader = csv.reader(csv_file, delimiter='|') for lines in csv_reader: edited_file.append(lines) return edited_file load_atlas('ala-acton.txt')you need quotes on line 10 and don't need them on line 5 (see above). That is assuming the txt file is in the current working directory |