相关疑难解决方法(0)

无需写入磁盘即可下载和解压缩.zip文件

我设法让我的第一个python脚本工作,从URL下载.ZIP文件列表,然后继续提取ZIP文件并将它们写入磁盘.

我现在无法实现下一步.

我的主要目标是下载并解压缩zip文件,并通过TCP流传递内容(CSV数据).如果我能逃脱它,我宁愿不将任何zip或解压缩的文件写入磁盘.

这是我当前的脚本,但不幸的是必须将文件写入磁盘.

import urllib, urllister
import zipfile
import urllib2
import os
import time
import pickle

# check for extraction directories existence
if not os.path.isdir('downloaded'):
    os.makedirs('downloaded')

if not os.path.isdir('extracted'):
    os.makedirs('extracted')

# open logfile for downloaded data and save to local variable
if os.path.isfile('downloaded.pickle'):
    downloadedLog = pickle.load(open('downloaded.pickle'))
else:
    downloadedLog = {'key':'value'}

# remove entries older than 5 days (to maintain speed)

# path of zip files
zipFileURL = "http://www.thewebserver.com/that/contains/a/directory/of/zip/files"

# retrieve list of URLs from the webservers
usock = urllib.urlopen(zipFileURL) …
Run Code Online (Sandbox Code Playgroud)

python unzip

69
推荐指数
7
解决办法
8万
查看次数

将zipfile解压缩到内存?

如何将zip解压缩到内存中?

我尝试(返回None.getvalue()):

from zipfile import ZipFile
from StringIO import StringIO

def extract_zip(input_zip):
    return StringIO(ZipFile(input_zip).extractall())
Run Code Online (Sandbox Code Playgroud)

python memory zip zipfile stringio

42
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×2

memory ×1

stringio ×1

unzip ×1

zip ×1

zipfile ×1