[Tutor] Remove last newline only in print / open / read function
Chris
ch2009 at arcor.de
Thu Apr 24 21:09:39 CEST 2014
Hi,
I'm a Python Newbie. Probably, this is a simple question.
I've a function that offers a ZIP-file for download:
def download_cert(form, config):
cn = form['cn'].value
serial = pki.util.serial_from_cn(config, cn)
files = pki.util.cert_files(config, cn, serial, True)
try:
name = path.join(tempfile.mkdtemp(), cn + '.zip')
zip = zipfile.ZipFile(name, 'w')
for file in files:
zip.write(file, path.basename(file))
zip.close() (1)
except:
pki.cgi.start_html('Internal error', True)
pki.cgi.show_error(str(sys.exc_info()[1]))
pki.cgi.show_link('Go Back')
pki.cgi.end_html()
else:
print 'Content-Type: application/zip'
print 'Content-Disposition: attachment;filename=' + cn + '.zip'
print
print open(name).read() (2)
os.remove(name)
os.rmdir(path.dirname(name))
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?
--
Chris
More information about the Tutor
mailing list