[Tutor] Remove last newline only in print / open / read function

Alan Gauld alan.gauld at btinternet.com
Fri Apr 25 10:36:46 CEST 2014

On 24/04/14 20:09, Chris wrote:

>        for file in files:
>           zip.write(file, path.basename(file))
>        zip.close() (1)
>        print open(name).read() (2)
> The ZIP file on the server is okay (1), but when it's sent to the client
> (2), there's a linefeed in the last line. This makes the zip invalid. So
> how can I remove the last linefeed only?

Can I first ask what makes you think there is an extra
linefeed at the end? Is it because of the print output?
You do remember that print adds a newline?

If you do

print open(name).read(),   # trailing comma suppresses newline

Does it look OK?

Or were already taking that into account?

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list