'Is there another way to have static variables depend on previous ones?

I would like to do something like this:

class Foo:
    A = some_constant
    B = Foo.A + 2
    ...

This doesn't work, because I am unable to reference Foo in the assignment of B.

I know using global variables would work:

A = some_constant
B = A + 2
class Foo:
    ...

Or assigning the variables after the class definition would work:

class Foo:
    ...
Foo.A = some_constant
Foo.B = Foo.A + 2

However, the first one does not provide the scoping that I would like, while the second one is rather clumsy in terms of my code organization, as it forces me to define these variables after the class definition.

Is there another way to solve this problem?



Solution 1:[1]

I don't see why this wouldn't work:

class Foo:
    A = some_constant
    B = some_constant + 2
    ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jafar Isbarov