# spezielle Sichtbarkeitsregeln im Klassen-Körper

a = 'global a'

class X():
    # außerhalb von Methoden erfolgt der Zugriff auf Attribute der Klasse über
    # einfache Namen; in Methoden sind dagegen für Klassen- und Instanz-Attribute
    # immer voll qualifizierte Namen zu verwenden

    a = 'a in class'
    b = a.replace('a ', 'b ')
    # X.a statt a ist nicht zulässig, da X nicht sichtbar ist
    #
    # NameError: name 'X' is not defined

    def hello(self):
        print('hello ', self)

    def print_vars(self, my=a): # hier ist X.a als a sichtbar
        print(my)               # a in class
        try:
            hello(1)            # hello() ist nicht sichtbar
        except Exception as e:
            print(repr(e))      # NameError("name 'hello' is not defined",)
        X.hello(2)              # X.hello() ist sichtbar
        self.hello()            # self.hello() ist ebenfalls sichtbar
        print(self.a)           # a in class
        print(X.a)              # a in class
        print(a)                # global a
        print(self.b)           # b in class
        print(b)                # NameError: name 'b' is not defined

    # im Klassenkörper ist hello() sichtbar
    hello(3)

x = X()
x.print_vars()
