csvfile_ = open(finishedFileName+num+\".csv\",\"w\",newline=\'\')
writ = csv.writer(csvfile_, dialect=\'excel\')
firstline = unicode(str(firstline))
try:
writ.writer
Unfortunately, 3to2
used the io.open()
call instead of the built-in Python 2 open()
function. This opened the file in text mode, which like on Python 3 expects Unicode input.
However, the csv
module does not support Unicode data; it certainly does not produce Unicode.
You'll either have to open the file in binary mode on Python 2:
mode = 'w'
if sys.version_info.major < 3:
mode += 'b'
csvfile_ = open(finishedFileName + num + ".csv", mode, newline='')
or use the built-in open()
call instead:
csvfile_ = open(finishedFileName + num + ".csv", 'wb')
where you have to use 'wb'
as the mode anyway.
If you are trying to write out unicode data, you'll have to encode that data before passing it to the csv.writer()
object. The csv module examples section includes code to make encoding from Unicode before writing a little easier.