instance creation

Jacek Generowicz jacek.generowicz at cern.ch
Tue Sep 24 11:20:34 CEST 2002


paulmg at digitalbrain.com (Paul MG) writes:

>     def load(self, id):
>       i = open("appointment"+str(id))
>       self = pickle.load(i)

> - Assigning to 'self' in the load method seems to really not work!

This associates the object returned by "pickle.load(i)" with the local
variable "self", and in the process removes any previous association
between "self" and an object; in your case, the association
established when the "load" method was called with "self" as an
argument. The only way to affect the object referred to by "self"
through "self" is by assigning to its attributes (or invoking member
functions which do this) ... along these lines:

tmp = pickle.load(i)
self.name = tmp.name
self.details = tmp.details

Though I suspect you could find neater ways by using a different
approach altogether.




More information about the Python-list mailing list