(May-20-2021, 04:46 PM)Onanism Wrote: TypeError: a bytes-like object is required, not 'str'When you make writer it's
bytes
because of wb
.Then
nrow
need to bytes as can not mix string
and bytes
one of the big changes when moving to Python 3 from 2.So convert before write.
>>> nrow = 'hello world' >>> type(nrow) <class 'str'> >>> nrow = nrow.encode() # Same as encode('utf-8') >>> type(nrow) <class 'bytes'>The other way is to make like this with
w
and use encoding(default is utf-8),but should specify like this as eg OS can mess it some times.ofile = open(self.ofname, "w", encoding='utf-8') writer = csv.writer(ofile, delimiter=',',