pickle fun

P

Pyenos

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.
 
P

Pyenos

Pyenos said:
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. :-|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,221
Latest member
TrinidadKa

Latest Threads

Top