[Tutor] Stacks and Stack underflow/Stack overflow

Hugo Arts hugo.yoshi at gmail.com
Sun Nov 20 02:40:19 CET 2011

On Sun, Nov 20, 2011 at 2:29 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 20/11/11 00:09, Steven D'Aprano wrote:
>> Walter Prins wrote:
>>> pickle files are binary files and you probably opened it as a text file.
>>> See here: http://docs.python.org/py3k/library/functions.html#open
>> Not so. Pickle protocol 0 is text, and it happens to be the default
>> protocol used if you don't instruct it different. So by default, pickles
>> are text unless you specifically use a binary protocol.
> Now that's interesting. All the examples I've sen use binary files.
> And even the examples on the documentation pages use binary mode.
> I just assumed therefore that pickles would, by their nature, be binary...

If you open the file in text mode and it happens to use a binary
protocol, things won't work because the binary might incorporate stuff
interpreted as newlines by the file object, with newline conversion
and such. If you open the file in binary it'll always work because the
file object doesn't touch the contents. So you always open the files
in binary mode to be on the safe side.


More information about the Tutor mailing list