pyfilesystem 一个简单试用

以前简单介绍过关于pyfilesystem 支持通用的文件系统访问,同时还提供了不少内部实现,可以快速使用,以下是一个关于
UserDataFS的简单试用

参考代码

  • app.py
from fs.appfs import UserDataFS
user_fs = UserDataFS('my_app')
if not user_fs.exists('data'):
    user_fs.makedir('data')
file_path = 'data/my_file.txt'
 
with user_fs.open(file_path, 'w') as file:
    file.write('Hello, UserDataFS!')
 
with user_fs.open(file_path, 'r') as file:
    content = file.read()
    print(content)
  • 基于协议格式的
import fs 
 
myfs = fs.open_fs("userdata://my_app:dalong")
 
file_path = "data/my_file.txt"
 
with myfs.open(file_path, "r") as file:
    content = file.read()
    print(content)
  • 效果
    以上会在系统的用户目录中创建数据,对于软件配置还是比较有用的

说明

以上只是一个简单使用说明,pyfilesystem 提供的通用文件api 还是比较方便的,对于项目中还是值得尝试的,对于数据科学的还是推荐基于fsspec

参考资料

https://docs.pyfilesystem.org/en/latest/reference/appfs.html
https://github.com/fsspec/filesystem_spec

posted on   荣锋亮  阅读(11)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-10-19 centos xxd 工具的安装
2023-10-19 httptoolkit 方便的http(s) 请求拦截工具
2023-10-19 pgspider 3.1.0 发布
2022-10-19 dremio dremio-sabot-logical 模块简单说明
2022-10-19 htmx 强大的html 工具
2021-10-19 dremio 开启新job ui 的开关
2020-10-19 govalidator 方便的golang 数据校验框架

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示