I want to read a file and write it back out. Here’s my code:
file = open( zipname , 'r' )
content = file.read()
file.close()
alt = open('x.zip', 'w')
alt.write(content )
alt.close()
This doesn’t work, why?????
Edit:
The rewritten file is corrupt
(python 2.7.1 on windows)
Read and write in the binary mode, ‘rb’ and ‘wb’:
The reason the text mode didn’t work on Windows is that the newline translation from ‘\r\n’ to ‘\r’ mangled the binary data in the zip file.