Methods of setting class attributes

Piotr Legiecki piotrlg at
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:

class a:

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 " = 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 = value?

Piotr Legiecki

More information about the Python-list mailing list