среда, 31 августа 2016 г., 14:09:16 UTC+7 пользователь ast написал:
> Hello
>
> I made few experiments about variables visibility
> for methods.
>
> class MyClass:
> a = 1
> def test(self):
> print(a)
>
> obj = MyClass()
> obj.test()
&
On Wednesday, August 31, 2016 at 12:09:16 AM UTC-7, ast wrote:
> Hello
>
> I made few experiments about variables visibility
> for methods.
>
> class MyClass:
> a = 1
> def test(self):
> print(a)
>
> obj = MyClass()
> obj.test()
>
> T
"dieter" a écrit dans le message de
news:mailman.63.1472630594.24387.python-l...@python.org...
"ast" writes:
You are right. And it is documented this way.
Thank you
--
https://mail.python.org/mailman/listinfo/python-list
"ast" writes:
> ...
> So it seems that when an object's méthod is executed, variables
> in the scope outside the object's class can be read (2nd example),
> but not variables inside the class (1st example).
>
> For 1st example, I know that print(MyClass.a) or print(self.a)
> would have work.
>
> A
Hello
I made few experiments about variables visibility
for methods.
class MyClass:
a = 1
def test(self):
print(a)
obj = MyClass()
obj.test()
Traceback (most recent call last):
File "", line 1, in
obj.test()
File "", line 4, in test
print(a)
NameEr