扩展peewee表达式抛出'Expression'对象是不可迭代的

时间:2017-09-26 13:16:04

标签: python peewee

我想在peewee中动态创建where子句。我知道我需要使用表达式,但无法运行它。这是我的代码:

  clauses = [
    (Docs.language_frst == 0), 
    (Docs.body_len <= max_body_len),
    (Docs.body_len >= min_body_len)
  ]

  if len(aValid_ids_used):
    clauses.extend( (Docs.id.not_in(aValid_ids_used)) )

  docids = Docs.select(Docs.id).where(reduce(operator.and_, clauses))

只要aValid_ids_used为空,代码运行正常。一旦aValid_ids_used不再为空,我要求延长条款我得到一个错误:

Traceback (most recent call last):   File "xyz.py", line 170, in <module>
clauses.extend( (Docs.id.not_in(aValid_ids_used)) ) 
TypeError: 'Expression' object is not iterable

2 个答案:

答案 0 :(得分:1)

您需要传递一个列表以进行扩展。您目前正在传递 let pi = CGFloat.pi let wave = Waves[0] let x = path.currentPoint.x let c = (2 * pi) / (wave.Wavelength * 30) let a = 30 * wave.Amplitude let y = a * sin(c * x) path.addLine(to: CGPoint(x: x + 2, y: y ))

Expression

e.g。

clauses.extend( (Docs.id.not_in(aValid_ids_used), ) )

答案 1 :(得分:1)

您可能希望使用list.append而不是list.extendextend将列表作为参数,而append只接受一个项目。