通过FTP下载zip文件并在Python中提取内存中的文件 [英] Download zip file via FTP and extract files in memory in Python
本文介绍了通过FTP下载zip文件并在Python中提取内存中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过ftp下载一个zip文件,但是然后在没有真正保存压缩文件的情况下提取文件。任何想法如何做到这一点?
ftplib
模块允许通过FTP下载文件。 zipfile
模块允许从zip文件中提取文件。
这里是关键字 io.BytesIO
类允许您将内存中的字节传递给任何需要文件的东西。 (在Python 2.x中, StringIO
模块提供了类似的功能。)
I'm trying to download a zip file via ftp, but then extract the files inside without ever actually saving the zip. Any idea how I do this?
解决方案
The ftplib
module allows downloading files via FTP.
The zipfile
module allows extracting files from a zip file.
Here's the key, the io.BytesIO
class allows you to pass in-memory bytes to anything that expects a file. (In Python 2.x, the StringIO
module provides similar functionality.)
这篇关于通过FTP下载zip文件并在Python中提取内存中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文