Classes in Python
Steven Taschuk
staschuk at telusplanet.net
Fri Apr 18 13:25:04 EDT 2003
Quoth Roy Smith:
[...]
> Extra credit for deranged minds: figure out a way to make:
>
> a = c()
> b = c()
>
> try:
> print b.x
> except AttributeError:
> print "wugga wugga"
>
> a.x = "foo"
>
> try:
> print b.x
> except AttributeError:
> print "wugga wugga"
>
> print "wugga wugga" and then print "foo". [...]
class c:
def __setattr__(self, attribute, value):
setattr(self.__class__, attribute, value)
Did you have something cleverer in mind?
--
Steven Taschuk staschuk at telusplanet.net
"I may be wrong but I'm positive." -- _Friday_, Robert A. Heinlein
More information about the Python-list
mailing list