I need to store a file directory in a variable because it will be used later. In my script below I want to print out the contents but I got a TypeError: 'file' object is not callable.
The script:
posfile = 'C:/Users/name/Desktop/textfile.txt'
csv_data=csv.reader(file(posfile))
count_test = 0
for row in csv_data:
count_test = count_test + 1
print count_test, row
Try:
You may also want to check that you haven’t changed the value of file some other place in your code.
should work.
If you’ve done something like file = somefile. Earlier in the code you could have problems. because file is no longer a file object.