0

我在使用以下代码时遇到问题:

start_date = dt.datetime(2012,01,01,00,00,00)
end_date = dt.datetime(2014,01,01,00,00,00)

sql="SELECT c.id extension, er.id, flow, filename, filesize, unread, er.cr_date, callerid, \
length, callid, info, party FROM extension_recording er, extension e, client c \
WHERE er.extension_id = e.id AND e.client_id = c.id AND c.parent_client_id = %s \
AND er.cr_date => %s AND er.cr_date <= %s" % (client_id) (start_date) (end_date)

cur.execute(sql)
recordings = cur.fetchall()

if recordings.rowcount == 0: sys.exit("No recordings for selected date range - exiting")

for recording in recordings:
    do stuff to recording

构建查询字符串会导致以下错误:

TypeError: 'str' object is not callable

我确定我遗漏了一些非常明显的东西,但我看不到树木的树木。

4

1 回答 1

4

将长线的末尾更改为:

... er.cr_date <= %s" % (client_id, start_date, end_date)

此外,当您使用它时,三引号对于长行更方便:

sql = """
    SELECT c.id extension, ...
    ... er.cr_date <= %s""" % (...
于 2013-01-11T16:35:58.743 回答