[Python-Dev] pickle.dump(..) interface change ... documentation

Brad Clements bkc at murkworks.com
Thu Feb 5 13:21:15 EST 2004

> > I just ran across something that looks like a very unfortunate interface
> > change in the pickle module:
> > 
> > Python 2.2:  dump(object, file[, bin])
> > Python 2.3:  dump(object, file[, protocol[, bin]])
> > 
> Are you sure you aren't misreading the docs?

I ran into this problem the other day and thought that pickle and cPickle were doing 
different things in 2.3 because I tried passing 4 parameters to cPickle dump() and 
got a different error than passing 4 parameters to pickle's dump()

>>> pickle.dump(x, f, 1, 1)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "D:\Python23\lib\pickle.py", line 1382, in dump
    Pickler(file, protocol, bin).dump(obj)
  File "D:\Python23\lib\pickle.py", line 199, in __init__
    raise ValueError, "can't specify both 'protocol' and 'bin'"
ValueError: can't specify both 'protocol' and 'bin'

>>> cPickle.dump(x, f, 1, 1)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: function takes at most 3 arguments (4 given)

I was pretty tired at the time and just said "huh.. well, I'll leave the code unchanged" 
which was cPickle.dump(x, f, 1)

The way I read the brackets in the docs:

dump(object, file[, protocol[, bin]])

you must supply object and file.

You may supply protocol.

If you supply protocol, you may also supply bin.

The nesting of bin within protocol's brackets make me read it that way. 

Should it instead be:

dump(object, file[, protocol | bin])


Brad Clements,                bkc at murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
http://www.wecanstopspam.org/                   AOL-IM: BKClements

More information about the Python-Dev mailing list