As the title says I'm getting an AttributeError
when I use csv.writerow()
.
I'm trying to add values into a csv file using csv.writerow()
.
The code:
import csv
class File:
def __init__(self, f):
self.f = f
def __add__(self, other):
with open(self.f, mode='a') as f:
writer = csv.writer(f, delimiter=',', quotechar='"')
f.writerow(str(other))
return self.__str__()
o = File('file.csv')
s = o + 2
I expected the code to add a new value to csv file and separate it from the other values with a comma.
The whole line from the error report looks like this:
AttributeError: '_io.TextIOWrapper' object has no attribute 'writerow'
.
writer.writerow(str(other))
notf.writerow(str(other))
. – martineau Feb 11 at 17:35