On Wed, Jul 27, 2011 at 5:30 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:

This recipe is pretty much the full extent of the proposal (perhaps
with the automatic type generation I mention in the discussion
section):
http://code.activestate.com/recipes/577810-named-values/



I like the NamedValue/namedvalue recipe. I prefer module constants like os.SEEK_END to nested names like os.Seek.End and this encourages that. If someone decides to change os module to:

    SEEK_END = namedvalue('SEEK_END', 2)

that won't break anything. For the simple enum case, a decorator could transform

    @enum
    class Color:
        red = 1
        green = 2

into:

    class Color:
        red = namedvalue('Color.red', 1)
        green = namedvalue('Color.green', 2)

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com