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

piet at cs.uu.nl piet at cs.uu.nl
Wed May 23 07:25:16 EDT 2001


>>>>> "Thomas Weholt" <thomas at cintra.no> (TW) writes:

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

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

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

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

Double the %, i.e. use 50%%
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list