0

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?

1 Answer 1

4

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'.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.