<div dir="ltr">I posted this question at <a href="http://codereview.stackexchange.com/questions/43619/proper-use-of-class-constants">http://codereview.stackexchange.com/questions/43619/proper-use-of-class-constants</a> but the people there apparently have fairly narrow definitions of "on-topic". I'm hoping someone here can lend some insight.<div>
<br></div><div>Basically I have a bunch of classes like this scattered around different modules in my project:</div><div><br></div><div>class MyObject:</div><div> ABOVE = 1</div><div> BELOW = 2</div><div><br></div>
<div>
def do_stuff(self, direction):</div><div> if direction == self.ABOVE:</div><div> # Do above stuff</div><div> elif direction == self.BELOW:<br> # Do below stuff</div><div><br></div>
<div>
<br></div><div>If I have a bunch of different classes in different modules that each use their own ABOVE and BELOW, what's the best way to handle it? </div><div><br></div><div>Should I extract these constants to their own class, maybe in its own module? Would creating a constants.py module be overkill?</div>
<div><br></div><div>Should I keep the class constants within the classes, since ABOVE and BELOW might mean slightly different things in different classes?</div><div><br></div><div>Is there a better / more pythonic solution to this design issue?</div>
</div>