Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3: gzip.open() and modes

https://docs.python.org/3/library/gzip.html

I am considering to use gzip.open(), and I am a little confused about the mode argument:

The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x' or 'xb' for binary mode, or 'rt', 'at', 'wt', or 'xt' for text mode. The default is 'rb'.

So what is the difference between 'w' and 'wb'?

The document states they are both binary mode.

So does that mean that there is no difference between 'w' and 'wb'?

like image 566
jeff00seattle Avatar asked Feb 02 '17 21:02

jeff00seattle


1 Answers

It means that r defaults to rb, and if you want text you have to specify it using rt.

(as opposed to open behaviour where r means rt, not rb)

like image 140
Jean-François Fabre Avatar answered Nov 15 '22 21:11

Jean-François Fabre