我设法让我的第一个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) 你能帮我写一个函数返回:
dict("file1.txt": list(<contents of file1>),
"file2.txt": list(<contents of file2>),
"file3.txt": list(<contents of file3>),
"file4.txt": list(<contents of file4>))
Run Code Online (Sandbox Code Playgroud)
输入时:
file.zip:
outer\
outer\inner1.zip:
file1.txt
file2.txt
outer\inner2.zip:
file3.txt
file4.txt
Run Code Online (Sandbox Code Playgroud)
我的尝试(以下除外):
WindowsError: [错误 32] 进程无法访问该文件,因为它正被另一个进程使用
“文件不是 zip 文件”
“文件不是 zip 文件”
AttributeError: ZipFile 实例没有属性“寻求”
我正在研究移动应用程序,需要在解压缩.apk文件后分析他们的代码.然而,解压缩的过程自然涉及大量的IO,这使得它不具有可扩展性,我在想是否可以将解压缩的数据保存在内存中,其中有几个变量代表它,从而节省了写入FS的麻烦.我有成千上万的应用程序需要分析,所以能够做这样的事情会大大加快我的过程.是否有人可以为我提出建议.我正在使用python.提前致谢