Skip to main content

A simple log module

Project description

pyeconfiguration

简易配置对象, 配置文件导入和保存.

安装

使用 pip 安装 econfiguration

pip install econfiguration

快速上手

import econfiguration

# 创建一个配置对象
config = econfiguration.Configuration()

# 使用对象属性创建配置条目
config.attr_value = 1

# 使用 key 创建配置条目
config['item_value'] = 2

# 使用对象属性访问配置条目
print(config.attr_value)
print(config.item_value)

# 使用 item 访问配置条目
print(config['attr_value'])
print(config['item_value'])

嵌套

import econfiguration

# 创建配置对象
config = econfiguration.Configuration()

# 嵌套配置对象
config.abc = econfiguration.Configuration()

# 设置配置条目
config.abc.value = 1

导入和保存文件

import econfiguration

# 在初始化时导入配置文件
config = econfiguration.Configuration('config.json', _type='json')

# 清除所有数据
config._con_clear_data()

# 从 json 文件中更新数据
config._con_update_from_json('config.json')

# 保存配置文件
config._con_asve_as_json('config.json')

Configuration 配置对象

Configuration(_file: Union[str, list, tuple] = ...,
              _type: str = 'json', read_only: bool = False)
# 创建配置对象
# _file: 需要导入的配置文件路径
# _type: 文件类型 ( 目前只接受 json )
# read_only: 设定这个对象为只读


._con_clear_data() -> None
# 清除所有条目数据

._con_set_read_only(value: bool) -> None
# 设置配置对象为只读模式

._con_is_read_only() -> bool
# 获取配置对象的只读模式描述

._con_update_from_data(data: dict) -> None
# 更新条目数据
# 当某项条目的数据类型为字典且键 ".con_is_configuration" 的值为 True 时将会初始化成一个 Configuration 对象.

._con_update_from_json(_file: Union[str, list, tuple] = ...) -> None
# 从 json 文件中更新数据

._con_get_data() -> dict
# 以字典的形式获取所有条目数据
# 数据类型为 Configuration 的条目也会分解成字典

._con_asve_as_json(_path: Union[str, list, tuple]) -> None
# 保存数据到 json 文件

._con_get_value(__key: str) -> Union[int, float, str, bool, list, tuple, dict]
# 获取指定条目的数据
# 当 key 不存在时返回 None

._con_set_value(__key: str, __value: Union[int, float, str, bool, list, tuple, dict]) -> None
# 设置条目数据
# key 不允许使用 "_con_" 字段开头
# value 不允许使用复杂数据类型

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

econfiguration-0.5.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

econfiguration-0.5.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file econfiguration-0.5.1.tar.gz.

File metadata

  • Download URL: econfiguration-0.5.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for econfiguration-0.5.1.tar.gz
Algorithm Hash digest
SHA256 5bed689cc0a3f657681f588f57422449d11b7fc3435e473197e1c308f51cb2b7
MD5 90a919d543362a7834f422e7178ac9d6
BLAKE2b-256 4bb78159343f271adfc72c13fede193f7774666a0c09232278dbce67f6c16e76

See more details on using hashes here.

File details

Details for the file econfiguration-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: econfiguration-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for econfiguration-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfbef3857cc9944700ead442696300d25c1136340c6d9623a357c1adf2a8e9eb
MD5 d4fd7198e5fddd83f651522d3e6adb04
BLAKE2b-256 d6c49a5e64447bb569a3ad6efdf8101a4bd313b3d099879ab96926bf6065fe2c

See more details on using hashes here.

Supported by

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