I have to convert the followin code written in Python 2 to Python3:
with open('C:/path_to_csv_file/fold1_1.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for row, timeseq in izip(fold1, fold1_t):
spamwriter.writerow([unicode(s).encode("utf-8") +'#{}'.format(t) for s, t in izip(row, timeseq)])
My Python 3 code is the following:
with open('C:/Users/path_to_csv_file/fold1_1.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for row, timeseq in zip(fold1, fold1_t):
for s, t in zip(row, timeseq):
bytes_var = s.encode('utf-8') +'#{}'.format(t).encode('utf-8')
spamwriter.writerow(bytes_var)
fold1 contains:
fold1 = ['¢©§','¢©§','¢©§']
fold1_t contains:
fold1_t =[[0, 15, 173999],[0, 457325, 306],[0, 62954, 432]]
When I try to execute the code above I get the following error:
TypeError: a bytes-like object is required, not 'str'
The variable bytes_var is type of bytes so normally it should work. Have I done something wrong with the conversion from Python2 to Python3 to get that error? Thank you.