python configuration file loading package
Project description
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'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl
.
File metadata
- Download URL: py_ztj_configfile-0.0.1-20190904062737-py3-none-any.whl
- Upload date:
- Size: 1.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6be277086c7e93cc5de4c149049587aacc34b4e74fc4948694531fad38596351 |
|
MD5 | f99c360fe2f464e3ed14b1bdc507118e |
|
BLAKE2b-256 | d25d097837478a5d91df0dcb92b3fb436dff24fb415ab8499f464fe86bc1bb2a |