Easy "here documents" ??

Doug Holton insert at spam.here
Tue Dec 21 01:58:09 CET 2004


> Jim Hill wrote:
> 
>> Is there a way to produce a very long multiline string of output with
>> variables' values inserted without having to resort to this wacky
>>
>> """v = %s"""%(variable)

No, it is currently not possible in Python without the hacks you have 
seen already.  Python is long overdue for simpler string interpolation 
as seen in many other scripting languages.

You should add a feature request to have this in Python 3.0, a.k.a. 
Python 3000: http://www.python.org/cgi-bin/moinmoin/Python3.0

Then you could simple do something like:

variable1 = 1
variable2 = 2

s = """
    v = ${variable1}
    v2's value is: ${variable2}
"""

However, Python 3.0 is likely years away.  If you want to know how to 
run code like this today, consult Fredrik Lundh.



More information about the Python-list mailing list