Reputation: 129
I'm trying to read the rows of a CSV file and print each row, but the code I've been using isn't opening the file or running the FOR loop. Any ideas?
import csv
domainFile = 'magtest.csv'
f = open(domainFile, 'ab+')
try:
reader = csv.reader(f)
print "file opened"
for row in reader:
print "Read domain: %s" %row
finally:
f.close()
Upvotes: 0
Views: 161
Reputation: 8786
ab+
mode opens a file for both appending and binary format, so therefore you cannot read in the contents if it is open to be appended to, you want r
to read it:
f = open(domainFile, 'r')
For more information about all of the different file modes, please refer to this documentation.
Upvotes: 3