Skip to main content

Ralsina.Me — Roberto Alsina's website

Advogato post for 2001-04-03 19:47:44

There should be a easy way to see who names you, so that northrup would see this:

In python, all mem­bers are in­stance mem­ber­s, if cre­at­ed out­side of the class def­i­ni­tion, un­less you specif­i­cal­ly cre­ate them as mem­bers of the class.

For ex­am­ple:

class a:
 pass
inst_a=a()
inst_b=a()
inst_a.memb_a=3
print inst_a.memb_a
3
print inst_b.memb_a
Traceback (innermost last):
File "<stdin>", line 1, in ?
AttributeError: memb_a
a.memb_class=5
print inst_b.memb_class
5

Hope that made any sense :-)


Contents © 2000-2023 Roberto Alsina