[Tutor] outputting long lines

Erik Price erikprice@mac.com
Sat Mar 8 11:57:02 2003


On Saturday, March 8, 2003, at 01:21  AM, Paul Tremblay wrote:

> Is there a tecnique for printing out long lines that span more than the
> length of your script?

One way to do it that doesn't sacrifice performance is to create a list 
of strings and then join them all together when they need to be treated 
as a single string.

 >>> text = [
...  'Here is a ',
...  'really long string ',
...  'that is broken up ',
...  'over multiple lines.'
...        ]
 >>> text
['Here is a ', 'really long string ', 'that is broken up ', 'over 
multiple lines.']
 >>> output = ''.join(text)
 >>> output
'Here is a really long string that is broken up over multiple lines.'
 >>>

Note that "output" is generated by calling the string method join() on 
an empty string, passing the list as the argument.


Erik




-- 
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org