[英]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.