0

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)==value)

But it just feels "wrong" -- is this the "correct" (or more aptly, "pythonic") way to do this?

tkone
  • 22,092
  • 5
  • 54
  • 78

1 Answers1

2
Users.select(getattr(Users.q, column)==value)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • d'oh! i'm using setattr to achieve the same thing on the input end, i should have thought about getattr on the output end. thank you! – tkone Mar 10 '11 at 13:40