problem with % operator on format string

vald at valis.amber.eu.org vald at valis.amber.eu.org
Thu Jun 26 04:04:23 CEST 2003


hello,
i just subscribed to this list, so first i'd like to greet all of you :)
i've recently discovered this great language and now i'm coding alot in 
it. today i ran into some problem with % operator on strings.

i have some database query, which i want to format nicely. it looks like:

 query = "select date(xxx, '\%d') from yyy where xxx
          like '%s%s\%'" % (year, month)

so it should produce something like that (year=2003, month=06)

 select date(xxx, '%d') from yy where xxx like '200306%'

but it doesn't work, the interpreter wants an integer except the two 
arguments, even if i (as you see) use an escape character '\' before %d. 
it seems that despite the esc-char, if next char is equal to 'd' or 's' 
it is considered as format-string %d or %s.. i wonder if there is any way 
to put this '%d' into the string so that it won't be considered as format?
i know i can just use '+' operator to create this query but it should be 
also possible with '%'.

this is the exact error i get:

in getDayEntries self.cursor.execute("select distinct date_format(edate, 
    '\%d') as data TypeError: int argument required

so even when there is \ before %d its still parsed and needs an int 
argument :/

that'd be all for this first time :)
thanks..

--
vald





More information about the Python-list mailing list