[Tutor] printing files

Alan Gauld alan.gauld at btinternet.com
Fri Mar 27 02:01:13 CET 2009


"Kent Johnson" <kent37 at tds.net> wrote
> On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD <alan.gauld at btinternet.com> 
> wrote:
>> Use '\n'.join(handle[1:])
>> It will create a string from your list with newline as separator.
>
> The lines from readlines() include the newlines already.

Ah, OK, I couldn't remember if readlines stripped them off or not.

>>> print>>out, handle[1:]
>>>
>>>  In the out file, it saves the lines as a list rather than as a string.

> use
>  out.writelines(handle[1:])

Or if you really want to use the print style

print>>out, ''.join(handle[1:])

ie join the lines using an empty string.

Alan G





More information about the Tutor mailing list