I don't quite understand why this happens. Why doesn't b have its own
version of r? If r was just an int instead of a dict, then it would.
1) You defined it at the class level
2) The lookup first looks for "self.r" on the instance, doesn't
find it, so looks at the class space
3) Dictionaries and lists are mutable -- you are changing the
contents "in place" (ie, in the class level object). Integers (all
numerics, tuples, and strings) are not mutable, so any "assignment" to
the name ("self.whatever = xxx") reattaches the name (self.whatever) to
the new object (xxx).
Compare the difference between your
... r = {}
... def setn(self, n):
... self.r["f"] = n
...
and one that used
def setn(self, n):
self.r = {"f" : n}
which is creating a new dictionary and then binding "self.r" to it
without changing the class level "r".
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/