[Tutor] here documents

Bill Campbell bill at celestial.net
Tue Jan 4 00:26:16 CET 2005


On Mon, Jan 03, 2005, Michael Powe wrote:
>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.

I think that triple quoting is probably what you want.

msg = '''
A bunch of text here, perhaps with %s insertion
''' % 'variable'

You will have to use the ``printf'' type features of the ``%''
operator in places where one could include variable names within
perl's double quotes or ``HERE'' types.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

DOS: n., A small annoying boot virus that causes random spontaneous system
     crashes, usually just before saving a massive project.  Easily cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.


More information about the Tutor mailing list