K
Klaus Oberpichler
Hello Python community,
my simple question is: When is the self reference to a class valid?
During playing around with python I got the following error message:
.... value = 1000
.... self.value = 2
....
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 3, in Test
NameError: name 'self' is not defined
When I do it a different way no error occurs:
.... value = 1000
.... def f(self):
.... self.value = 2
....
When is the reference to its own class is generated and valid? What is the
reason bihind that behaviour?
Best regards
Klaus
my simple question is: When is the self reference to a class valid?
During playing around with python I got the following error message:
.... value = 1000
.... self.value = 2
....
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 3, in Test
NameError: name 'self' is not defined
When I do it a different way no error occurs:
.... value = 1000
.... def f(self):
.... self.value = 2
....
When is the reference to its own class is generated and valid? What is the
reason bihind that behaviour?
Best regards
Klaus