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 不允许使用复杂数据类型

其它

字典重载

使用 Configuration._con_update_from_data 更新数据时 当某项数据的类型为 dict 且其中包含 '.con_is_configuration' 且值为 True, 那么这个字典会被重载成 Configuration 对象

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.3.tar.gz (3.7 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.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: econfiguration-0.5.3.tar.gz
  • Upload date:
  • Size: 3.7 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.3.tar.gz
Algorithm Hash digest
SHA256 6ad661ebd91bb539fc3f6fdcf83b8beaf36bdffec6f0e7beaeae2458124e61d9
MD5 c1ad17b87a2afe87ccdb035e3c86da8b
BLAKE2b-256 4c175a09033acd3a6cfefda07e004c51aab1c9a968f58125fee0e97e7428cae8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: econfiguration-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 753cf7c421b5bb368ef80d29b75996689d3918e0e10ee1aa789b87339c1072c0
MD5 fef5fc742e26f83f46648354ff8a03c5
BLAKE2b-256 686d4740490f0809e67ed6f7f6ef70397c4336e8fc7d82b1f50c3dcc3e9bf89c

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