How do I put % in a format sting?
John Salerno
johnjsal at NOSPAMgmail.com
Thu Oct 5 16:15:49 EDT 2006
Gregory Piñero wrote:
> How do I put % in a format sting?
>
> For example I want this to work:
>
>>>> sql_template="""SELECT ENTRY FROM LOOKUP WHERE FIELDNAME LIKE '%s%V'"""
>>>> sql_template % 'userdef103'
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> TypeError: not enough arguments for format string
>
>
>
Put it immediately after the string:
sql_template="""SELECT ENTRY FROM LOOKUP WHERE FIELDNAME LIKE '%s%V'"""
% 'userdef103'
But I think SQL has other recommended methods. At least with SQLite, it
is recommended you not use Python's %s formatter but instead the "?"
formatter.
More information about the Python-list
mailing list