小编Vir*_*hiu的帖子

如何从生成器中读取tarfile?

在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中执行相同的操作?

python generator tar bytesio python-2.7

7
推荐指数
1
解决办法
372
查看次数

如何在OS X上安装Python 2.6的pip?

我有一个OS X系统,我需要为python 2.6安装一个模块.这两个pipeasy_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)

下载get_pip.py …

python macos python-2.6

5
推荐指数
1
解决办法
1万
查看次数

如何使用Python实现并行gzip压缩?

使用python进行大文件压缩给出了一个很好的示例,说明了如何使用例如bz2纯粹在Python中压缩非常大的文件集(或大文件)。

Pigz说,利用并行压缩可以做得更好。就我所知(和Google搜索)而言,我找不到在纯Python代码中等效的Python。

是否有并行的Python实现pigz或等效的实现?

python zlib

5
推荐指数
2
解决办法
2473
查看次数

标签 统计

python ×3

bytesio ×1

generator ×1

macos ×1

python-2.6 ×1

python-2.7 ×1

tar ×1

zlib ×1