%s shortcut?

thebjorn BjornSteinarFjeldPettersen at gmail.com
Wed Sep 26 00:17:44 EDT 2007


On Sep 26, 4:55 am, james_027 <cai.hai... at gmail.com> wrote:
> hi i have something like this
>
> cursor.execute("""
>             select c.name,
>                 (select from ap_invoice i where Month(i.date) = 1 and
> Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') jan,
>                 (select from ap_invoice i where Month(i.date) = 2 and
> Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') feb,
>                 (select from ap_invoice i where Month(i.date) = 3 and
> Year(i.date) = %s and i.customer_id = c.id and i.status != 'CAN') mar
>             from ap_customer c
>             order by %s""",
>             [year, order_by])
>
> what I could like to happen is ... since the first three %s points to
> the same year variable, how do I let python know it without doing
> [year ,year, year, order_by] ... This should be 12 I just cut it down
>
> Thanks
> james

You could do [year]*12 + [order_by] like so:

>>> [1970] * 12 + ['foo']
[1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970,
1970, 'foo']
>>>

I don't know which database you're using, but the above doesn't look
like SQL'92...

-- bjorn




More information about the Python-list mailing list