I'm trying to read a bzip2 compressed text file with python's bz2, but lines read are always in binary, no matter the mode set.
I simply tried this:
import bz2
with bz2.open("my_file.xml.bz2", mode='r') as fin:
for line in fin:
# some processing
If I understand the documentation correctly, the "r" mode should open the file as text. However it's binary, with or without mode="r".
What am I doing wrong?
check the official doc.
The mode argument can be any of 'r', 'rb', 'w', 'wb', 'x', 'xb', 'a' or 'ab' for binary mode, or 'rt', 'wt', 'xt', or 'at' for text mode. The default is 'rb'.