[Chicago] Python style question: class constants

Gang Huang doc.n.try at gmail.com
Thu Mar 6 20:41:39 CET 2014


Why not just create a base class to inherit from, since it's scattered
everywhere.
On Mar 6, 2014 11:38 AM, "Thomas Johnson" <thomas.j.johnson at gmail.com>
wrote:

> I posted this question at
> http://codereview.stackexchange.com/questions/43619/proper-use-of-class-constantsbut the people there apparently have fairly narrow definitions of
> "on-topic". I'm hoping someone here can lend some insight.
>
> Basically I have a bunch of classes like this scattered around different
> modules in my project:
>
> class MyObject:
>     ABOVE = 1
>     BELOW = 2
>
>      def do_stuff(self, direction):
>         if direction == self.ABOVE:
>             # Do above stuff
>         elif direction == self.BELOW:
>             # Do below stuff
>
>
> 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?
>
> Should I extract these constants to their own class, maybe in its own
> module? Would creating a constants.py module be overkill?
>
> Should I keep the class constants within the classes, since ABOVE and
> BELOW might mean slightly different things in different classes?
>
> Is there a better / more pythonic solution to this design issue?
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20140306/0f73489c/attachment.html>


More information about the Chicago mailing list