Use of variables form outside the class.

Oleg Broytmann phd at emerald.netskate.ru
Thu Jul 29 09:37:25 EDT 1999


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.





More information about the Python-list mailing list