Use of variables form outside the class.

Ralph Gauges ralph.gauges at eml.villa-bosch.de
Thu Jul 29 10:37:33 EDT 1999


Oleg Broytmann wrote:
> 
> On Thu, 29 Jul 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?
> 
> x = 1
> 
> class X
>    def set_x(self):
>       self.x = 2
> 
>    def set_global_x(self):
>       global x
>       x = 2
> 
> > Peter Thorstenson
> > The Newbie
> 
> Oleg.
> ----
>     Oleg Broytmann        Netskate/Inter.Net.Ru        phd at emerald.netskate.ru
>            Programmers don't die, they just GOSUB without RETURN.


I guess I should read more carefully. I thought you were
defining the variable inside the class, but outside the
methods.
Sorry for the wrong answer. Olegs answer is the right one.

Ralph




More information about the Python-list mailing list