开发者

using eval to programmatically define an SQLQuery q object

开发者 https://www.devze.com 2023-02-16 12:55 出处:网络
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 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号