python - csv module python3.1 -
im using following in python2.x ;
import csv f = open('test.csv', 'wb') writer = csv.writer(f) writer.writerow((fpath, md5sum, size)) # <str>, <str>, <int>
this works without problems. however, when run in python3, typeerror.
writer.writerow((fpath, md5sum, size)) typeerror: write() argument 1 must bytes or buffer, not str
of course, writing out data file in opened in non-binary mode trick, way unicode handled in py3 , wish encode data before writing file , decode when reading it.
how solve problem?
f = open('test.csv', 'w', encoding='utf-8', newline='')
Comments
Post a Comment