vars between classes

Marc Tardif intmktg at Gloria.CAM.ORG
Sat May 27 10:31:03 EDT 2000


How can I maintain variables between classes and superclasses without
passing explicitly as methods arguments? For instance:

class first:
  def __init__(self, var):
    self.var = var
    self.myMethod()

  def myMethod():
    print "first:", self.var
    second(self.var)
    print "last:", self.var

class second(first):
  def myMethod():
    print "second:", self.var
    self.var = 3

def test(var):
  first(var)

if (__name__=='__main__'):
  test(2)

Problem is, I would like the printed line containing "last" to output "3"
as defined in the second class but it outputs "2" instead. Basically, I'd
like to be able to pass variable pointers instead of variables values or
perhaps maintain global variables. Whichever solution is most appropriate,
I'd appreciate suggestions and comments.

Marc Tardif




More information about the Python-list mailing list