I'm using SQLObject and want to programmatically build a query using the .q objects (or some other way) -- but do not want to revert to actual SQL.
I'm trying to do something like:
column = 'name'
value = 'todd'
Users.select(Users.q.column==value)
I've got this:
Users.select(eval('Users.q.%s' % column)==v开发者_Python百科alue)
But it just feels "wrong" -- is this the "correct" (or more aptly, "pythonic") way to do this?
Users.select(getattr(Users.q, column)==value)
精彩评论