Reputation: 3
I need your help~ I have a LF problem when I use 'wirtestr'. the text have been written into zip well but It comes in one line without line breaks. Only I could find the delimiter which looks like square has circle in the middle of it, maybe hex code for newline. If anyone knows about this problem please help!
fp = StringIO(line)
value = fp.getvalue()
filename1 = 'D:/re/m/11.txt'
filename2 = 'D:/re/m/dd.zip'
archive = zipfile.ZipFile(filename2, 'w', zipfile.ZIP_DEFLATED)
finfo = zipfile.ZipInfo(filename1)
archive.writestr(finfo, value)
Upvotes: 0
Views: 700
Reputation: 2646
The ZipFile.writestr
method writes files from Python string in binary mode. All text files added with this method must then have explicit '\r\n'
line endings for Windows programs to read them correctly afterwards.
Your original content had 'universal line ending' within python, which usually only turn into CRLF ('\r\n'
) when going through a text-mode output file.
That seems to be fixed in python 3.x
Upvotes: 1