attributes of Python classes

beliavsky at aol.com beliavsky at aol.com
Wed Mar 17 19:05:42 EST 2004


I have started using classes with Python and have a question
about their use.

In Python, 'attributes are all "public" and "virtual" in C++ 
terms; they're all accessible everywhere and all looked up 
dynamically at runtime' (Quoting "Learning Python", 2nd. ed., 
p367). It seems to me that two good conventions are to 

(1) initialize all attributes in the __init__ function
(2) avoid creating new attributes elsewhere that are not initialized in
    __init__

I have not followed these conventions so far, and sometimes
it is difficult for me to tell what attributes an instance of
a class has. Are these conventions good?



More information about the Python-list mailing list