Re: ``pickling'' and ``unpickling''

2006-04-06 Thread Peter Hansen
[EMAIL PROTECTED] wrote: > Hi, > I am new in Python World.I want to know what is mean by ``pickling'' > and ``unpickling'' ? > And how can we used it?Please Give Me some links of Picking Examples. > Thanks You can generally answer such questions yourself

Re: ``pickling'' and ``unpickling''

2006-04-06 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Lonnie Princehouse" <[EMAIL PROTECTED]> wrote: > Pickling is the Python term for serialization. See > http://en.wikipedia.org/wiki/Serialization > > Suppose you want to save a Python object "x" to a file... > > output_file = open('my_pickle', 'wb') # open a fi

Re: ``pickling'' and ``unpickling''

2006-04-05 Thread Lonnie Princehouse
Pickling is the Python term for serialization. See http://en.wikipedia.org/wiki/Serialization Suppose you want to save a Python object "x" to a file... output_file = open('my_pickle', 'wb') # open a file import pickle pickle.dump(x, output_file) # write x to the file output_file.close() ...

``pickling'' and ``unpickling''

2006-04-05 Thread sushant . sirsikar
Hi, I am new in Python World.I want to know what is mean by ``pickling'' and ``unpickling'' ? And how can we used it?Please Give Me some links of Picking Examples. Thanks Sushant -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickling and unpickling inherited attributes

2005-11-02 Thread Alex
> > > OK, but do be aware that slots was intended solely as a > memory-conservation measure where large numbers of objects are being > created. You are therefore subverting its true intent by using it to > limit the assignment of extra attributes (and there has been much recent > discussion on thi

Re: Pickling and unpickling inherited attributes

2005-11-01 Thread Steve Holden
Alex wrote: > Thanks to both Alex Martelli and Steve Holden.. We need __slots__ for > other reasons, too long to explain, but basically to prevent assignment > of extra attributes. > > I ended up changing child classes this way: > > def __getstate__(self): > return(Parent.__getstate__

Re: Pickling and unpickling inherited attributes

2005-11-01 Thread Alex
Thanks to both Alex Martelli and Steve Holden.. We need __slots__ for other reasons, too long to explain, but basically to prevent assignment of extra attributes. I ended up changing child classes this way: def __getstate__(self): return(Parent.__getstate__(self), self.C) def __se

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Steve Holden
, 'w') >>>>cPickle.dump(obj, File) >>>>File.close() >>>> >>>>file1=open('test', 'r') >>>>objct=cPickle.load(file1) >>>>file1.close() >>>>objct.A > > > Traceback (most recent call l

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Alex Martelli
Alex <[EMAIL PROTECTED]> wrote: > I have a serious problem and I hope there is some solution. It is > easier to illustrate with a simple code: > > >>> class Parent(object): > __slots__=['A', 'B'] > def __init__(self, a, b): > self.A=a; self.B=b > def __getstate__(s

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Alex
Thanks so much! It makes perfect sense and I am sure it will work now. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Sam Pointon
Of course, in __setstate__, there should be a tup = list(tup) as well - sheer forgetfulness and a confusing name in one. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Sam Pointon
The reason the state of obj.A and obj.B aren't preserved is because your __getstate__ and __setstate__ don't preserve them - they only save obj.C, and you don't make a call to the parent class's respective methods. Here's what I mean: >>> import pickle >>> class Child(Parent): __slots__=[

Re: Pickling and unpickling inherited attributes

2005-10-30 Thread Alex
Sorry, I copied and pasted a wrong piece from shell at one part of the code: objct.Z=4 was in fact obj.Z=4 and it did refuse to accept Z (because it is not in __slots__). But the question remains: why the value of attribute A is not preserved during pickling and unpickling and what can be done

Pickling and unpickling inherited attributes

2005-10-30 Thread Alex
File "", line 1, in -toplevel- objct.A AttributeError: A >>> objct.C 1 Its own attribute (C) value is restored but the value of an inherited attribute (A) is not. I tried pickling protocol 2, and module pickle instead of cPickle, all with the same result. What can be done?! Or maybe nothing can be done? I would greatly appreciate an advice. A lot of code is written, but now we have a need for pickling and unpickling objects and discovered this problem. -- http://mail.python.org/mailman/listinfo/python-list