Methods of setting class attributes
piotrlg at sci.pam.szczecin.pl
Wed Jul 25 10:57:34 CEST 2001
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:
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?
More information about the Python-list