The two are not of the same type:
>
---------------------------------
In : import sets
In : s1=sets.Set([1,2,3])
>
In : s2=set([1,2,3])
>
In: type(s1)
Out: <class 'sets.Set'>
>
In : type(s2)
Out: <type 'set'>
>
In : s1==s2
Out: False # oops!
>
In: s2==set(s1)
Out: True # aha!
----------------------------------
>
You'll have to just cast:
unpickled_set=s et(unpickled_se t)
>
-Nick V.
Or you may have this done automatically by hacking the Set class:
s = Set([1,2,3])
x = pickle.dumps(s)
print pickle.loads(x)
This doesn't work though if you have already pickled the Set before
replacing its __reduce__, so it may not necessarily be what you want.
If there is a way around it, I'd like to know it.
At Wednesday 8/11/2006 05:26, George Sakkis wrote:
>Or you may have this done automatically by hacking the Set class:
>
>from sets import Set
>import cPickle as pickle
>
>Set.__reduce __ = lambda self: (set, (self._data,))
>
>s = Set([1,2,3])
>x = pickle.dumps(s)
>print pickle.loads(x)
>
>
>This doesn't work though if you have already pickled the Set before
>replacing its __reduce__, so it may not necessarily be what you want.
>If there is a way around it, I'd like to know it.
Perhaps registering a suitable reduce function in the copy_reg module.
If the sets were pickled alone, and it's not too much trouble, using:
a_set = set(a_set) just after unpickling may be enough.
And if they were instance attributes, __setstate__ on the class can
do the conversion.
--
Gabriel Genellina
Softlab SRL
_______________ _______________ _______________ _____
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Comment