[Tutor] here documents
Alan Gauld
alan.gauld at freenet.co.uk
Tue Jan 4 00:54:06 CET 2005
There was a detailed thread on this recently either here
or on usenet group comp.lang.python...
The bottom line was to use string formatting and triple
quoted strings...
msg = '''
A very long string that overspills
onto multiple lines and includes
my name which is %{name}s
and a number which is my age: %{age}d
'''
print msg % vars()
HTH,
Alan G.
----- Original Message -----
From: "Michael Powe" <michael at trollope.org>
To: <tutor at python.org>
Sent: Monday, January 03, 2005 10:54 PM
Subject: [Tutor] here documents
> Hello,
>
> In perl, I create variables of fairly involved text using here
> documents. For example,
>
> $msg = <<"EOF";
> a bunch of text here.
> ...
> EOF
>
> Is there an equivalent method in python? I usually use this method
> when creating help messages for scripts -- put all the text into a
> variable and the 'print $msg' for the output. I find it an easy way
> to produce formatted text.
>
> Now, I'm trying to switch over to python and want to recreate or
adapt
> my processes.
>
> Thanks.
>
> mp
>
>
More information about the Tutor
mailing list