Q:

Making an enumeration of a lookup table in a database with SQLAlchemy?

So I've got this lookup table in a database that looks something like this:
-----------------
| Code | Id     |
-----------------
| Good | 1      |
| Bad  | 2      |
-----------------

And I want to make a Python object that looks something like this:
>>> Codes.Good
1
>>> Codes.Bad
2

I've been doing using a hack of patching together the type function, a raw SQL query, and Session.execute. For example:
>>> results = Session.execute("select code, id from codes")
>>> d = {}
>>> [d[result.code] = result.id for result in results]
>>> Codes = type("Codes", (object,), d)

Is there a better built-in way in SQLAlchemy to do this? 

A:

The creator of SqlAlchemy just recently put up a post on doing just this:
http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/

