[Tutor] Multi-line statements with comments

Kirby Urner urnerk@qwest.net
Sat, 29 Dec 2001 07:42:05 -0800


Kirby Urner, 4D Solutions
 

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org] On Behalf
Of Danny Yoo
Sent: Friday, December 28, 2001 5:42 PM
To: Jim Angstadt
Cc: tutor@python.org
Subject: Re: [Tutor] Multi-line statements with comments

On Fri, 28 Dec 2001, Jim Angstadt wrote:


> However, the use of the continuation character does not permit one to
> have comments within the string.  In regular expressions, there is a
> way to disreguard whitespace within the RE, and add comments, which
> makes a lengthy expression more readable.  ( I'm referring to VERBOSE
> in python or x in perl. )
> 
> What is a good technique for commenting multi-line statements that are
> not REs?

Note:  you can also have comments in multi-lines where the goal is to 
define a sequence or mapping.

 >>> j = [
	1,2, # this is a
	3,4  # list
	]
 >>> j
 [1, 2, 3, 4]

So if you have your heart set on commenting each line of a string, 
spread across multiple lines, you could do something like:

 >>> mylist = ["here we",            # beginning of string
               " are testing",       # middle of string
               " a way to comment",  # etc.
	         " string formations"  # finis
	        ]

then join it all together at the end (comments automagically gone):
 
>>> thestring = ''.join(mylist)
>>> thestring
'here we are testing a way to comment string formations'


Kirby