Skip to content Skip to sidebar Skip to footer

Should Class-specific "constants" Still Be Declared At Module Level?

In PEP 8, it's stated that 'Constants are usually defined on a module level […]'. This makes sense for the standard library, where constants tend to pertain to the entire module

Solution 1:

Clearly, class-based constants belong in the class. Stick with your second example. Remember PEP8 is not handed down from the Almighty. It's just good ideas: tradition, reason and experience can temper the meaning of scripture.

Hungrarian_prefix_notation is needless. That's one reason you have classes.

Solution 2:

Who consumes the constant? You say "I'm currently writing a module, however, where the constants are all related to individual classes." So put the constant in the class.

Post a Comment for "Should Class-specific "constants" Still Be Declared At Module Level?"