best way to have enum-like identifiers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mh@pixar.com

    #1

    best way to have enum-like identifiers?

    I currently have a 2-dim hash, indexed by two strings:

    template['py']['funcpre']
    template['py']['funcpost']
    ...

    but I would prefer to have these indexed by constants of
    some kind, since this seems a bit more natural:

    template[py][funcpre]
    template[py][funcpost]
    ...

    Currently I'm just putting this at the top of the file:

    py=1
    funcpre=2
    funcpost=3
    ...

    but I'm curious if there's a better way of doing this,
    some kind of enum-like thing or somesuch.

    Many TIA!
    Mark

    --
    Mark Harrison
    Pixar Animation Studios
  • Pete Forman

    #2
    Re: best way to have enum-like identifiers?

    mh@pixar.com writes:
    Currently I'm just putting this at the top of the file:
    >
    py=1
    funcpre=2
    funcpost=3
    ...
    That can be done more compactly with

    py, funcpre, funcpost = range(3)

    give or take 1.

    but I'm curious if there's a better way of doing this,
    some kind of enum-like thing or somesuch.
    https://launchpad.net/munepy describes itself as yet another Python
    enum implementation. Its author is Barry Warsaw.
    --
    Pete Forman -./\.- Disclaimer: This post is originated
    WesternGeco -./\.- by myself and does not represent
    pete.forman@wes terngeco.com -./\.- the opinion of Schlumberger or
    http://petef.22web.net -./\.- WesternGeco.

    Comment

    Working...