Sorry für das schlechte Subject, aber mein Problem ist genau, dass ich keinen Namen für mein Thema finde. Ich habe neulich folgendes Phänomen beobachtet (python 3.10.4):
Code: Alles auswählen
>>> __BAR = "hello world"
>>> class Foo:
... def baz(self):
... return __BAR
...
>>> f = Foo()
>>> f.baz()
Traceback (most recent call last):
Cell In[5], line 1
f.baz()
Cell In[3], line 3 in baz
return __BAR
NameError: name '_Foo__BAR' is not defined
>>> _Foo__BAR = "hello world"
>>> class Foo:
... def baz(self):
... return __BAR
...
>>> f = Foo()
>>> f.baz()
'hello world'
>>>