me at privacy.net
Fri Oct 15 22:06:16 CEST 2004
On Wed, 13 Oct 2004 16:27:10 +0200,
Andreas Kostyrka <andreas at kostyrka.org> wrote:
> On Wed, Oct 13, 2004 at 01:32:38PM +0200, Matthias Teege wrote:
>> 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?
> Try: "'%%%s%%'"
Be careful with the quotation marks, too; consider the case that value
contains a quotation mark (or an apostrophe).
I don't know what kind of database and/or API you're using, but DB-API
compliant (Python PEP 249) libraries will put the right quotation marks
(if any) around your strings *and* quote any internal troublesome
Never play leapfrog with a unicorn.
More information about the Python-list