i Don't get why it makes trouble

azrael jura.grozni at gmail.com
Thu Aug 13 15:26:07 EDT 2009


On 13 kol, 21:12, "Jan Kaliszewski" <z... at chopin.edu.pl> wrote:
> Me wrote:
> > 13-08-2009 azrael <jura.gro... 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
>
> [snip]
>
> PS. If you use Python 2.6 or newer, better use .format() method
> (then you can use also a list):
>
> >>> 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 = '{0}' AND o.naziv = \
> ... '{1}' AND z.naziv = '{2}' AND d.naziv = '{3}' AND v.naziv = '{4}'\
> ... """.format(*j)
>
> Cheers,
> *j
>
> --
> Jan Kaliszewski (zuo) <z... at chopin.edu.pl>

Thanks Worked fine for me. I was a freakin idiot. I forgot about using
a tuple. damn lists :D

Thanks for the debuginig of my thoughts and actions.

thnx



More information about the Python-list mailing list