i Don't get why it makes trouble

Jan Kaliszewski zuo at chopin.edu.pl
Thu Aug 13 15:06:47 EDT 2009


13-08-2009 azrael <jura.grozni at gmail.com> wrote:

>>>> j
> [u'Tata', u'Oriovac', u'PrimorskoGoranska', u'hrvatska', u'Kuna']
>>>> len(j)
> 5
>>>> h = """SELECT distinct u.id_ulica, o.id_opcina, z.id_zupanija,  
>>>> d.id_drzava, v.id_valuta FROM   ulica as u, opcina as o, zupanija as  
>>>> z, drzava as d, valuta as v  WHERE  u.naziv = '%s' AND o.naziv = '%s'  
>>>> AND z.naziv = '%s' AND d.naziv = '%s' AND v.naziv = '%s'""" % (j)
> Traceback (most recent call last):
>   File "<string>", line 1, in <string>
> TypeError: not enough arguments for format string
>
>
> I want to format the string. the list has five elements and the string
> has five placeholder but it wont format the string

j must be a tuple -- so either define it as

     (u'Tata', u'Oriovac', u'PrimorskoGoranska', u'hrvatska', u'Kuna')

or when using it, wrap it with tuple() constructor:

     h = """...........""" % tuple(j)

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list