python persistence

castironpi at gmail.com castironpi at gmail.com
Mon Mar 31 23:28:08 EDT 2008


On Mar 31, 9:27 pm, George Sakkis <george.sak... at gmail.com> wrote:
> On Mar 31, 8:51 pm, castiro... at gmail.com wrote:
> > On Mar 31, 7:14 pm, 7stud <bbxx789_0... at yahoo.com> wrote:
>
> > > On Mar 31, 5:31 pm, castiro... at gmail.com wrote:
>
> > > > Can you have a Python object stored entirely on disk?
>
> > > import cPickle as cp
>
> > > class Dog(object):
> > >     def __init__(self, name):
> > >         self.name = name
>
> > > d = Dog("Spot")
>
> > > f = open("data.txt", "w")
> > > cp.dump(d, f)
> > > f.close()
>
> > > f = open("data.txt")
> > > stored_obj = cp.load(f)
> > > print stored_obj.name
>
> > > --output:--
> > > Spot
> > >>> import pickle
> > >>> pickle.loads( pickle.dumps( type('None',(),{}) ) )
>
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "C:\Programs\Python\lib\pickle.py", line 1303, in dumps
> >     Pickler(f, protocol).dump(obj)
> >   File "C:\Programs\Python\lib\pickle.py", line 221, in dump
> >     self.save(obj)
> >   File "C:\Programs\Python\lib\pickle.py", line 283, in save
> >     f(self, obj) # Call unbound method with explicit self
> >   File "C:\Programs\Python\lib\pickle.py", line 697, in save_global
> >     (obj, module, name))
> > pickle.PicklingError: Can't pickle <class '__main__.None'>: it's not
> > found as __
> > main__.None
>
> http://docs.python.org/lib/node317.html- Hide quoted text -

What's involved in Can you have a Python object stored entirely on
disk?  No process to access: changes to contents written back.



More information about the Python-list mailing list