problems using % in strings with %(var)s replacements

Alex Martelli aleaxit at yahoo.com
Wed May 23 06:23:29 EDT 2001


"Thomas Weholt" <thomas at cintra.no> wrote in message
news:jPLO6.2171$556.193068 at juliett.dax.net...
> Say I got a string s = "%(number)s among 50% are efficient for
> %(customer_name)s."
    ...
> I see the % in 50% is the problem but how can I use the %-char in strings
> and still use %(...)s replacements??

Just "double up" the percent-character:

D:\py21>python
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> s="%(number)s among 50%% are efficient for %(custname)s"
>>> number=23
>>> custname='Alex'
>>> print s%globals()
23 among 50% are efficient for Alex
>>>


Alex






More information about the Python-list mailing list