Methods of setting class attributes
Piotr Legiecki
piotrlg at sci.pam.szczecin.pl
Wed Jul 25 04:57:34 EDT 2001
Hi
I'm C++ user and new to Python. I don't know what is the proper method
of setting attribute value in a class. I thought that this is ok:
class a:
atr1=0
atrb=1
.....
Well, after a little tour through python source codes I have changed my
point of view.
1. There is no explicit attributes declarations (hm...)
2. I'v found such a information in python's docs:
......
__setattr__(s, name, val) called when setting an attr
(inside, don't use "self.name = value"
use "self.__dict__[name] = val")
.....
This method (among others) has any class. So setting any attribute
should always be done by __setattr__() and not smiple self.name = value?
Why?
--
Regards
Piotr Legiecki
More information about the Python-list
mailing list