pickle fun
Pyenos
pyenos at pyenos.org
Wed Dec 20 21:27:36 EST 2006
Pyenos <pyenos at pyenos.org> writes:
> class pickle_service:
> import cPickle as p
>
> # accept list as arg then serialize it to a file
> def serialize(some_list,picklefile):
> f=file(picklefile,"w")
> p.dump(some_list,f) # so dumped this shit to the file
> f.close()
> # which one is the pickle? the file? no. just need the string of the name of file.
>
> # unserialize what? picklefile of course ;)
> def unserialize(some_pickle):
> f= file(some_pickle) # wtf is going on here: open file for unpickling
> return p.load(f) # unpickled: store it somewhere
>
> class testpickleservice:
> import pickle_service as p
>
> p.serialize(["f","u","c","k"," ",["you"]],"testpickle")
> print p.unserialize("testpickle")
>
> AHAHAHAHA. funny.
just remove class and save them as separate files. i was too dumb to
realize that i need to do self explicitly here. :-|
More information about the Python-list
mailing list