Pickle

G

gerardob

I have a problem using Pickle inside a class object.

The following code works:

m2 = markov_model.MarkovModel()
m2 = pickle.load(open("prueba", 'rb'))
print m2.n

However, if I create the following method inside markov_model.MarkovModel:

def load_model_from_file(self, name):
try:
file = open(name, 'rb')
self = pickle.load(file)
file.close()
except pickle.PicklingError:
print "PicklingError"

and then run:

m2 = markov_model.MarkovModel()
m2.load_model_from_file("prueba")
print m2.n

it says that 'MarkovModel' object has no attribute 'n'. If the printing of
'n' i put it inside (at the end) of the method load_model_from_file as
'print self.n' it works.

How can i solve this?
Thanks
 

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,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top