Class Variable Question

Robert Johnson rjohnson at exotic-eo.com
Mon Apr 9 10:33:24 EDT 2001


I am new to Python and I just read something that I thought was peculiar.
Is it true that a user can add to the variables of a class just by naming
the new variable?

Like:

ClassObject.var1=5

Would this create a variable "var1" inside the class even though the creator
of the class never intended it to be there (there was no var1 originally)?
If I mistype the variable in my code, a new variable inside the class is
created rather than flagging the error?  Is there a way to prevent this so
users cannot add variables?  It seems to me that the user could just
override a class with unrelated data.

Thanks in advance,

Robert Johnson





More information about the Python-list mailing list