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

Simon Brunning SBrunning at trisystems.co.uk
Wed May 23 06:34:44 EDT 2001


> From:	Thomas Weholt [SMTP:thomas at cintra.no]
> 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??
 
Just double up the % character:

s = "%(number)s among 50%% are efficient for %(customer_name)s."

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list