[Tutor] outputting long lines

Charlie Clark charlie@begeistert.org
Sat Mar 8 12:27:02 2003


On 2003-03-08 at 18:00:07 [+0100], tutor-request@python.org wrote:
> Subject: 
> 
> Is there a tecnique for printing out long lines that span more than the 
> length of your script?
> 
> For example, I am trying to output this line:
> 
> 1  if self.__token_info == 'cw<nt<type______':
> 2              self.__write_to_foot_obj.write('\
> 3              mi<dv<op<footnote<at<num>%s' % self.__footnote_count)
> 
> My output is:
> 
>             mi<dv<op<footnote<at<num>2
> 
> I don't want this huge space at the beginning. I want:
> 
> mi<dv<op<footnote<at<num>2
> 
> There are ugly ways to achieve what I want. I could output the text with 
> several write lines. I could get rid of the space in line 3 above. But I 
> was thinking there is probably an easeir and more elegant solution.

"easier" and "elegant" sounds like Python to me!!!

You can have pretty much any number of line breaks within a function call 
(ie. within the brackets) allowing you to break things down as they suit 
you.

You only need to use "\" for a new line inside a string but you can use 
long string quotes (either """ string """ or ''' string ''') instead

if self.__token_info == 'cw<nt<type______':
	self.__write_to_foot_obj.write(
	"mi<dv<op<footnote<at<num>%s"
	% self.__footnote_count
	)

Does that help?

Charlie