[Python] Python class attribute: How to refer to parent class attribute implicitly? [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 1, 2025.

  1. Stack

    Stack Membro Participativo

    I can't understand why this isolated code don't work :

    class SwitchSchema():

    CONF_CONST_POWER = "constant_power"

    class LightSchema(SwitchSchema):

    TestVar = CONF_CONST_POWER

    print(LightSchema.TestVar)


    Error: File "main.py", line 7, in <module>, NameError: name 'CONF_CONST_POWER' is not defined

    Are the class attributes not inherited ?

    Continue reading...

Compartilhe esta Página