I have a configuration file where I specify what database to connect to (i.e., the database connection can only be known at runtime), and class definitions like this:

def _makeUserClass(connection):
    class User(SQLObject):
        _connection = connection
        _fromDatabase = True
        _cacheValues = False
        _table = 'users'
        groups = sqlobject.RelatedJoin('Group')
        # ...
    return User

I think this is terrible. I used to just paste in the class definition everywhere I needed it, in methods and such; that was worse. At least this way there's one text that defines it.

I think there's something simple I must be missing. How can I avoid all this?


Jared Jennings