Class static variables
Alex Martelli
alex at magenta.com
Mon Jul 24 13:16:24 EDT 2000
"Guillaume" <forums at memoire.com> wrote in message
news:8lh1eo$a74$1 at nnrp1.deja.com...
>
> Axel understood perfectly the goal of my question and the way I would
I think you mean me (Alex) rather than Axel, but, anyway:
> First I used constructs like if name=="x": but in fact the use of try:
> makes it more general (no need to know the attribute name). Inheritance
[snip]
> try:
> A.__dict__[name]
> A.__dict__[name]=value
> return None
> except KeyError:
> self.__dict__[name]=value
I think that just as general, and probably better, might be:
if A.__dict__.has_key(name):
A.__dict__[name]=value
else:
self.__dict__[name]=value
It appears to me that this expresses more directly the intent:
if the class's dictionary already has this name as a key, then
set it to the new value, else, set the instance's dictionary.
Alex
More information about the Python-list
mailing list