首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pyfilesystem可以组合模式吗?

pyfilesystem可以组合模式吗?
EN

Stack Overflow用户
提问于 2020-10-09 20:05:42
回答 2查看 19关注 0票数 1

我想使用具有模式组合的pyfilesystem。例如,我想在FTP服务器上打开一个tar文件,然后执行ftp+tar://user:password@host:port/path/file.tar.gz.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-10-12 17:36:17

不是这样的,但是TarFS构造函数接受打开的文件。因此,下面这些方法应该是可行的:

代码语言:javascript
复制
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()
票数 1
EN

Stack Overflow用户

发布于 2020-10-12 23:29:31

我最终得到了这样的结果:

代码语言:javascript
复制
@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_
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64279722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档