<p dir="ltr">Why not just create a base class to inherit from, since it's scattered everywhere. </p>
<div class="gmail_quote">On Mar 6, 2014 11:38 AM, "Thomas Johnson" <<a href="mailto:thomas.j.johnson@gmail.com">thomas.j.johnson@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I posted this question at <a href="http://codereview.stackexchange.com/questions/43619/proper-use-of-class-constants" target="_blank">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>
<br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div>