ubuntu12.04上的SQLAlchemy query出现TypeError,但在Windows上没有

2024-06-28 20:34:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个为python2.7编写的脚本。我让它在几台不同的机器上工作,所以我知道它可以“移动”。在

我现在正在设置一个ubuntu box(v12.04)。在

同样的代码在ubuntu中失败:

instance = session.query(formats_table).\
filter(formats_table.c.formatid==FormatID, 
       formats_table.c.puid==PUID, 
       formats_table.c.formatversion==FormatVersion, 
       formats_table.c.formatmimetype==FormatMIMEType).all()

在windows中,它运行良好,不会引起任何问题

在ubuntu中失败的原因是:

^{pr2}$

我能做些什么来找出哪里出了问题?在

我假设这一行被解析为5个不同的参数,而不是两个(会话.查询)and(filter),这表示括号没有被正确解析?在


Tags: instance代码脚本box机器sessionubuntutable
1条回答
网友
1楼 · 发布于 2024-06-28 20:34:13

你有两个不同版本的SQLAlchemy。在

SQLAlchemy's ^{} method:

filter(*criterion)

apply the given filtering criterion to a copy of this Query, using SQL expressions.

e.g.: session.query(MyClass).filter(MyClass.name == 'some name')

Multiple criteria are joined together by AND (new in 0.7.5):

session.query(MyClass).filter(MyClass.name == 'some name', MyClass.id > 5)

请注意,在0.7.5之前,在一个filter调用中不能有多个条件,必须链接多个filter调用才能获得相同的效果。在你的情况下,这看起来像:

instance = session.query(formats_table).\
filter(formats_table.c.formatid==FormatID).\
filter(formats_table.c.puid==PUID).\
filter(formats_table.c.formatversion==FormatVersion).\
filter(formats_table.c.formatmimetype==FormatMIMEType)

因此,引用的“参数”是传递给filter的关键字参数,在Ubuntu版本附带的SQLAlchemy版本中只能有一个参数,并且您提供了四个参数。另一个您看不到的参数是instance对象(通常称为self),它在您调用实例方法时自动传递。在

相关问题 更多 >