quoting %

Richie Hindle richie at entrian.com
Wed Oct 13 13:45:33 CEST 2004


[Matthias]
> I need a string like this "foo '%value%'" for a database query but
> print "'%%s%'"%value gives me TypeError: not all arguments converted
> during string formatting. How does I quote the "%" sign in this case?

Double up the percent signs:

>>> print "foo '%%%s%%'" % 'spam'
foo '%spam%'

-- 
Richie Hindle
richie at entrian.com




More information about the Python-list mailing list