在Python中用生成器创建一个zip文件?描述了从一堆文件中将.zip写入磁盘的解决方案.
我在相反的方向上有类似的问题.我被给了一个发电机:
stream = attachment.iter_bytes()
print type(stream)
Run Code Online (Sandbox Code Playgroud)
而且我想将它管道传输到tar gunzip文件对象:
b = io.BytesIO(stream)
f = tarfile.open(mode='r:gz', fileobj = b)
f.list()
Run Code Online (Sandbox Code Playgroud)
但我不能:
<type 'generator'>
Error: 'generator' does not have the buffer interface
Run Code Online (Sandbox Code Playgroud)
我可以在shell中解决这个问题:
$ curl --options http://URL | tar zxf - ./path/to/interesting_file
Run Code Online (Sandbox Code Playgroud)
如何在给定条件下在Python中执行相同的操作?
我有一个OS X系统,我需要为python 2.6安装一个模块.这两个pip和easy_install-2.6的失败:
# /usr/bin/easy_install-2.6 pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Download error: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Download error: unknown url type: https -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
Run Code Online (Sandbox Code Playgroud)
使用python进行大文件压缩给出了一个很好的示例,说明了如何使用例如bz2纯粹在Python中压缩非常大的文件集(或大文件)。
Pigz说,利用并行压缩可以做得更好。就我所知(和Google搜索)而言,我找不到在纯Python代码中等效的Python。
是否有并行的Python实现pigz或等效的实现?