[Tutor] removing file from zip archive.
w chun
wescpy at gmail.com
Sat Apr 1 01:26:57 CEST 2006
> How can we remove one file inside of a zip archive?
>
> import zipfile
> ziparchive = zipfile.ZipFile('test.odt', 'r')
> xmldata = ziparchive.read('content.xml')
> ziparchive.close <--- ADD "( )" HERE TOO
Sophon,
You can remove any number of files from a ZIP file, but it has to be
processed manually by you. When you read() a file from a ZIP archive,
you actually have all the data with you, i.e. xmldata.
All you have to do is to open another file to write it out to disk, i.e.,
f = open('content.xml', 'w')
f.write(xmldata)
f.close()
hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Tutor
mailing list