[Pythonmac-SIG] Replace placeholder in string with content of ONE variable???

Donovan Preston dsposx at mac.com
Wed Aug 27 15:03:04 EDT 2003


On Wednesday, August 27, 2003, at 1:42 PM, Eric Wichterich wrote:

> Hello,
>
> Can anyone help me out? I want to replace a string with several 
> placeholders (%s) with the content of ONE variable.
> Here is a small (silly) example:
>
> action = "barking"
> print "My %s dog keeps %s all the time." % action
>
> The output I am looking for is "My barking dog keeps barking all the 
> time."

 >>> "My %(verb)s dog keeps %(verb)s all the time." % {'verb': 'barking'}
'My barking dog keeps barking all the time.'




More information about the Pythonmac-SIG mailing list