instance creation

Jacek Generowicz jacek.generowicz at
Tue Sep 24 05:20:34 EDT 2002

paulmg at (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.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