Variables escaping quotes
Matt Gerrans
mgerrans at mindspring.com
Mon Aug 19 23:57:56 EDT 2002
I don't know what this has to do with escaping quotes, but here an more
braindead approach than the other two suggestions:
print "The husband only had $x minutes to live before his wife, in a rage of
redundant adjectives, blah, blah, blah".replace('$x',str(10))
Hmm... Or maybe the smart thing to do is replace the $x with a %d and then
use string formatting. Assuming you are doing this for localization or
something like that and have a lot of text with this $x form of substition,
you might want to make a little script that zips through it all replacing $x
with %s, then you can use string formatting from that point on (and maybe go
through by hand and change some of the %s to %d or whatever, as
appropriate -- as long as you are coverting the data to string before the
formatting, it will work in the mean time with the brute force approach).
More information about the Python-list
mailing list