Variables escaping quotes

Greg Ewing see_reply_address at something.invalid
Tue Aug 20 00:45:39 EDT 2002


Blistex wrote:

> Is there a way for a variable to escape quotation marks?  For example:
> 
> x=10
> print "The husband only had $x minutes to live before his wife,...


Use some variant of %-formatting, e.g.


   print """The husband only had %s minutes to live before his wife, in a rage
   of fury and wrath, would descend upon him like a thousand, shrieking
   banshees, to rend his life (not to mention his manhood) from his cowering
   body.""" % x

Note also the use of """ (triple quotes), because that allows the
string literal to span multiple lines.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list