我想使用具有模式组合的pyfilesystem。例如,我想在FTP服务器上打开一个tar文件,然后执行ftp+tar://user:password@host:port/path/file.tar.gz.
发布于 2020-10-12 17:36:17
不是这样的,但是TarFS构造函数接受打开的文件。因此,下面这些方法应该是可行的:
with open_fs("ftp://user:password@host:port/") as ftp_fs:
with ftp_fs.open("path/file.tar.gz") as tar_file:
my_tar = TarFS(tar_file)
my_tar.tree()发布于 2020-10-12 23:29:31
我最终得到了这样的结果:
@contextmanager
def open_url(url: str,
mode: str = "r",
create: bool = False,
buffering: int = -1,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: str = "",
**options: Any,
) -> typing.IO:
writeable = True if "w" in mode else False
dir_url, file_name = os.path.split(url)
with open_fs(dir_url, writeable, create) as fs_:
with fs_.open(file_name, mode, buffering, encoding, errors, newline,
**options) as file_:
yield file_https://stackoverflow.com/questions/64279722
复制相似问题