Skip to main content

(pickle+lz4 based) save Python objects in binary to the file system and manage them.

Project description

Files3 Python Object Management

  1. English Version
    1. Intallation
    2. Quick Start
    3. Advanced
    4. Notice
    5. Cmd Command
    6. Last
  2. Chinese Version
    1. Intallation
    2. Quick Start
    3. Advanced
    4. Cmd Command
    5. Last

Installation

pip install files3

# After installation, you can use the command in cmd:

f3assoc .inst
to associate the '.inst' file with the 'f3open' program.

Quick Start

from files3 import files
f = files()  # save pyfile in current directory with default suffix '.inst'
 
## save python object (modify is also like save)
f.set('a', 1)
 
## check if file exist
f.has('a')  # True
 
## load python object
print(f.get('a'))  # 1
 
## delete file
f.delete('a')

files(dir:str="", type:str=".inst")

Advanced

from files3 import files
f = files()
 
## Save
f.a = 1
# f['a'] = 1
 
## load
print(f.a)  # 1
# print(f['a'])  # 1
 
## delete
del f.a
# del f['a']
 
## check if file exist
'a' in f  # False
 
 
## Use other key not only str:
# 1. tuple or list
f[('a', 'b')] = [1, 2]
print(f.a, f.b, f['a'], f['b'])  # 1, 2, [1, 2]
 
# 2. slice
print(f[:])  # [1, 2]
# print(f[...])  # [1, 2]
 
# 3. function
print(f[lambda x: x == 'a'])  # 1
 
# 4. re
print(f[re.compile('a')])  # 1
 
del f[...]

Notice

There are some special case that you can't save:

  1. save pfbool object
  2. use f_A to save instance which contain f_A. (but you can use f_B to save it.)
  3. object which do not have __getstate__ and __setstate__ method

Cmd Command


f3 [name] [type] -d [dir]  # open a files3 object
f3open [fpath]  # open a files3 object
f3assoc [type]  # associate the '.type' file with the 'f3open' program

Last

It's really convinent but, because pickle is not safe, so mayn't use it to load the file you don't trust. However, if you do not care about it like me, you can use it to bring you a good programming experience.

安装files3

pip install files3

# 安装后,可以在cmd中使用命令:

f3assoc .inst
将'.inst'文件关联到'f3open'程序。

快速开始

from files3 import files
f = files()  # 保存py文件在当前目录,后缀为'.inst'
 
## 保存python对象(修改也是这样)
f.set('a', 1)
 
## 检查文件是否存在
f.has('a')  # True
 
## 加载python对象
print(f.get('a'))  # 1
 
## 删除文件
f.delete('a')

files(dir:str="", type:str=".inst")

高级用法

from files3 import files
f = files()
 
## 保存
f.a = 1
# f['a'] = 1
 
## 加载
print(f.a)  # 1
# print(f['a'])  # 1
 
## 删除
del f.a
# del f['a']
 
## 检查文件是否存在
'a' in f  # False
 
 
## 使用其他键不仅仅是str:
# 1. tuple or list
f[('a', 'b')] = [1, 2]
print(f.a, f.b, f['a'], f['b'])  # 1, 2, [1, 2]
 
# 2. slice
print(f[:])  # [1, 2]
# print(f[...])  # [1, 2]
 
# 3. function
print(f[lambda x: x == 'a'])  # 1
 
# 4. re
print(f[re.compile('a')])  # 1
 
del f[...]

注意

有一些特殊情况不能保存:

  1. 保存pfbool对象
  2. 使用f_A保存包含f_A的实例。 (但是您可以使用f_B保存它。)
  3. 没有__getstate__和__setstate__方法的对象

Cmd命令


f3 [name] [type] -d [dir]  # 打开一个files3对象
f3open [fpath]  # 打开一个files3对象
f3assoc [type]  # 将'.type'文件关联到'f3open'程序

最后

这确实很方便,但是由于pickle不安全,因此可能不要使用它来加载您不信任的文件。 但是,如果您不像我一样不怎么关心它,那么可以使用它为您带来良好的编程体验。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

files3-0.5.4.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

files3-0.5.4-py3-none-any.whl (17.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page