Python Pickle

gerardob gberbeglia at
Mon Apr 12 11:23:04 EDT 2010

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):
		file = open(name, 'rb')			
		self = pickle.load(file)			
	except pickle.PicklingError: 
		print "PicklingError"

and then run:

m2 = markov_model.MarkovModel()
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?

View this message in context:
Sent from the Python - python-list mailing list archive at

More information about the Python-list mailing list