pickling the objects returned by array.array()

Discussion in 'Python' started by John Machin, Sep 1, 2005.

  1. John Machin

    John Machin Guest

    Googling for "pickle array" in comp.lang.python yields old messages that
    show a PickleError -- plus one message where Alex Martelli writes "I am
    but an egg" :O)
    Looks like arrays are NOW (2.4.1) pickleable but not unpickleable -- see
    below.
    I appreciate that arrays are inherently not pickleable because of the
    type code.
    However:
    (1) Anyone know why/when the world changed?
    (2) If we had alternative constructors like array.iarray(contents) in
    parallel to array.array('i', contents), those objects could be
    pickled/unpickled -- yes/no?

    Cheers,
    John
    ====================
    Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pickle, array
    >>> class Foo(object):

    .... pass
    ....
    >>> foo = Foo()
    >>> foo.ia = array.array('i', [3,2,1])
    >>> foo.ia

    array('i', [3, 2, 1])
    >>> s = pickle.dumps(foo, -1)
    >>> bar = pickle.loads(s)

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "C:\Python24\lib\pickle.py", line 1394, in loads
    return Unpickler(file).load()
    File "C:\Python24\lib\pickle.py", line 872, in load
    dispatch[key](self)
    File "C:\Python24\lib\pickle.py", line 1097, in load_newobj
    obj = cls.__new__(cls, *args)
    TypeError: array() takes at least 1 argument (0 given)
    ===========
     
    John Machin, Sep 1, 2005
    #1
    1. Advertising

  2. John Machin wrote:
    > Looks like arrays are NOW (2.4.1) pickleable but not unpickleable


    Please file a bug report and assign to me.


    Raymond Hettinger
     
    Raymond Hettinger, Sep 2, 2005
    #2
    1. Advertising

  3. Raymond Hettinger wrote:
    > John Machin wrote:
    >> Looks like arrays are NOW (2.4.1) pickleable but not unpickleable

    >
    > Please file a bug report and assign to me.


    Done. http://python.org/sf/1281383

    Reinhold
     
    Reinhold Birkenfeld, Sep 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Guettler

    Pickling Objects inherited from dict (Bug?)

    Thomas Guettler, Nov 5, 2003, in forum: Python
    Replies:
    1
    Views:
    305
    Michael Hudson
    Nov 5, 2003
  2. danny
    Replies:
    2
    Views:
    298
    Greg Chapman
    Apr 23, 2004
  3. Shahin Saadati

    pickling objects in jython

    Shahin Saadati, Sep 7, 2005, in forum: Python
    Replies:
    0
    Views:
    309
    Shahin Saadati
    Sep 7, 2005
  4. Littlefield, Tyler
    Replies:
    7
    Views:
    139
    mblume
    Apr 6, 2013
  5. Chris Angelico
    Replies:
    0
    Views:
    126
    Chris Angelico
    Apr 6, 2013
Loading...

Share This Page