In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "how to operate the file of the python zipfile module", the content is detailed, the steps are clear, the details are handled properly, I hope that this article "how to operate the file of the python zipfile module" can help you solve your doubts, the following follows the editor's ideas slowly in depth, together to learn new knowledge.
1. Used to read zip files
> > import zipfile, os > os.chdir ('C:\') # move to the folder with example.zip > exampleZip = zipfile.ZipFile ('example.zip') > exampleZip.namelist () [' spam.txt', 'cats/',' cats/catnames.txt', 'cats/zophie.jpg'] > spamInfo = exampleZip.getinfo (' spam.txt') > > spamInfo.file_size13908 > > spamInfo.compress_size3828 > 'Compressed file is% sx smaller'% (spamInfo.file_size / spamInfo.compress_size) 2)) 'Compressed file is 3.63x smallerbread' > > exampleZip.close ()
2. The second parameter zipfile.ZIP_DEFLATED in the zipfile.ZipFile () method specifies the deflate compression algorithm, which is very effective for all types of data.
This code will create a new ZIP file called new.zip, which contains the contents of spam.txt compression.
Just like writing to a file, write mode deletes all the original contents in the ZIP file. If you only want to add the file to the original ZIP file, transfer an as the second parameter to zipfile.ZipFile () to open the ZIP file in add mode.
> import zipfile > newZip = zipfile.ZipFile ('new.zip', 'w') > newZip.write (' spam.txt', compress_type=zipfile.ZIP_DEFLATED) > newZip.close () here, this article "how to operate the file of python zipfile module" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.