Use of variables form outside the class.

Ralph Gauges ralph.gauges at eml.villa-bosch.de
Thu Jul 29 09:27:22 EDT 1999


Peter Torstenson wrote:
> 
> I declare a variable "x" right in the beginning of a module.
> Later I declare a class with function defs.
> I managed to declare varibles inside the class and address them by putting
> "self." in front of the variable.
> How do I reach the "x" variable that is outside any class from inside the
> class functions?
> 
> Peter Thorstenson
> The Newbie

By referencing it via 'classname.x' instead of
`instancename.x' (or 'self.x').
This variable does not belong to an instance of the class
but to the class itself. This also means that you always use
the same variable no matter if you use different instances
of the class. But I guess this is what you want.

Ralph




More information about the Python-list mailing list