How do I import in_

3,984 views
Skip to first unread message

mmblnfrn

unread,
May 16, 2009, 10:14:40 AM5/16/09
to pylons-...@googlegroups.com
Hi,

I've problems to write a filter function:

user_q = meta.Session.query(model.BPUser)
user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
model.BPUser.state.in_([0,1]))).first()

I've tried to load the in_ function by

>>> from sqlalchemy import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_
>>> from sqlalchemy.sql import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_
>>> from sqlalchemy.sql.expression import in_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name in_


Any hints ?

vbr
Matt

Wichert Akkerman

unread,
May 16, 2009, 12:40:41 PM5/16/09
to mmblnfrn, pylons-...@googlegroups.com
Previously mmblnfrn wrote:
>
> Hi,
>
> I've problems to write a filter function:
>
> user_q = meta.Session.query(model.BPUser)
> user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
> model.BPUser.state.in_([0,1]))).first()

in_ is a method on the column instance, there is no need to import it.

Wichert.

--
Wichert Akkerman <wic...@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.

Ben Bangert

unread,
May 16, 2009, 1:44:02 PM5/16/09
to pylons-...@googlegroups.com
On May 16, 2009, at 7:14 AM, mmblnfrn wrote:

> I've problems to write a filter function:
>
> user_q = meta.Session.query(model.BPUser)
> user = user_q.filter(and_(model.BPUser.name=='%s' % username, \
>
> model.BPUser.state.in_([0,1]))).first()

Additionally,there's no reason to do the string sub like that, this
should be fine:

user = user_q.filter(and_(model.BPUser.name==username, \

model.BPUser.state.in_([0,1]))).first()

Or if you have some condition where username might not be the right
type, str() it.

Cheers,
Ben

Reply all
Reply to author
Forward
0 new messages