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

Thomas Weholt thomas at cintra.no
Wed May 23 05:56:31 EDT 2001


Say I got a string s = "%(number)s among 50% are efficient for
%(customer_name)s."

I want to replace 'number' with 42 and 'customer_name' with Acme Inc.

Trying to do a simple
>>> s % {'number':42,'customer_name':'Acme Inc.'}
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: not enough arguments for format string
>>>

I see the % in 50% is the problem but how can I use the %-char in strings
and still use %(...)s replacements??

Thomas





More information about the Python-list mailing list