[英]Zip file not seekable
我正在尝试对压缩文件进行一些文件操作。 我有点困惑为什么文件像对象.open返回一个不可寻找的文件。 任何人都可以对此有所了解吗?
这是我正在使用的代码。 我怎样才能使file_like可以搜索?
zipped_archive = ZipFile(filepath, mode='r')
file_like = zipped_archive.open(file_name, mode='r')
file_like.seekable() # returns False
在Python 3.7版( 问题 )中修复
一个非常有用和简单的工作帮助我添加可搜索到我使用的文件:
def add_seekable_to_file(f):
"""
If file f does not has seekable function -
add seekable function that will always return true
Args:
f: the file
Returns: the file f with seekable function
"""
if not hasattr(f, "seekable"):
# AFAICT all the filetypes that STF wraps can seek
f.seekable = lambda: True
add_seekable_to_file(datazip.fp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.