I'm trying to convert a Python 2.x version of this code:
out_chunk = open('out.txt','w+b')
chunks.append(out_chunk) # out_chunk is just a list of strings like ['a', 'b', ...]
out_chunk.writelines(chunk)
into Python 3.x version. If I run the above code in Python 3.x directly, I get an error like below, which is expected:
Traceback (most recent call last):
File "C:/Users/Desktop/es/prog.py", line 145, in <module>
ob.external_sort()
File "C:/Users/Desktop/es/prog.py", line 70, in my_func
out_chunk.writelines(chunk)
TypeError: a bytes-like object is required, not 'str'
Is there a way to write list of strings as bytes in Python 3.x? Or should I just write as a list of strings (and take the performance hit, maybe?)