[Tutor] is this a bug global i ???

Pujo Aji ajikoe at gmail.com
Tue Jun 14 10:38:32 CEST 2005

I have code like this:

class A:
  def __init__(self,j):
    self.j = j
  def something(self):
    print self.j
    print i            # PROBLEM is here there is no var i in class A
but it works ???

if __name__ == '__main__':
  i = 10
  a = A(5)

I don't define global i but it will takes var i from outside of class A.

Can somebody explain this ???


More information about the Tutor mailing list