Python ConfigFile Package
说明
这是一个 Python 配置文件加载模块,主要解决 yaml, json 配置文件的快速加载。
依赖
pip install PyYAML==5.1.2
使用
import os.path
from configfile import ConfigFile
config_dir = os.path.dirname(os.path.abspath(__file__))
configfile = ConfigFile(config_dir)
# 加载配置文件
print(configfile.load('config'))
# 加载配置文件
print(configfile.load('config', '/srv/config'))
配置文件定期加载
import json
import time
import os.path
from framework.configfile.configfile import ConfigFile
timestamp1 = time.time()
timestamp2 = False
config_dir = os.path.dirname(os.path.abspath(__file__))
configfile = ConfigFile(config_dir)
def callback():
global timestamp1
global timestamp2
if timestamp2 is False:
timestamp2 = timestamp1
else:
timestamp2 = time.time()
return json.dumps({"timestamp": timestamp2})
file_path = configfile.get_file_path('expire', configfile.json_suffix)
print(configfile.expire(file_path, callback, 3))
print(configfile.load('expire'))
time.sleep(1)
print(configfile.expire(file_path, callback, 3))
print(configfile.load('expire'))
time.sleep(3)
print(configfile.expire(file_path, callback, 3))
print(configfile.load('expire'))
Metadata
Release files for py-ztj-configfile 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl | Python 3 | none | any | Details for py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl |
Release files / py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl
| Download URL | py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl |
|---|---|
| Size | 1.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6be277086c7e93cc5de4c149049587aacc34b4e74fc4948694531fad38596351
|
|
BLAKE2b-256 checksum How to use checksums |
d25d097837478a5d91df0dcb92b3fb436dff24fb415ab8499f464fe86bc1bb2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
|
Security for py-ztj-configfile 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.