1

I'm having trouble with the following code:

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

Building the query string results in the following error:

TypeError: 'str' object is not callable

I'm sure I am missing something blindingly obvious, but I can't see the wood for the trees.

1
  • Why (client_id) (start_date) (end_date)? Commented Jan 11, 2013 at 16:36

1 Answer 1

3

Change the end of your long line to this:

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

Also, while you are at it, triple-quotes are more convenient for long lines:

sql = """
    SELECT c.id extension, ...
    ... er.cr_date <= %s""" % (...
Sign up to request clarification or add additional context in comments.

1 Comment

A thousand thanks! Still struggling with Python syntax. Works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.