Reputation: 11
my code:
# opening CSV
with open('notables.csv', 'w') as notables:
file_write=csv.writer(notables, delimiter = ',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
# write
# TO DO: how to get the values to write as well?
file_write.writerow(data1)
# close file
file_write.close()
my error:
file_write.close()
AttributeError: '_csv.writer' object has no attribute 'close'
Am I suppose to close a csv file when done? If so, how?
Upvotes: 1
Views: 1309
Reputation: 11188
As others pointed out, you're trying to close something that isn't close-able. Just remove that line, and because you opened the file in a with ...
context, you don't need to close anything, Python will manage that for you:
# opening CSV
with open('notables.csv', 'w') as notables:
file_write=csv.writer(notables, delimiter = ',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
# write
# TO DO: how to get the values to write as well?
file_write.writerow(data1)
Upvotes: 1