Skip to main content

The advance version of origin configparser.

Project description

Python | 配置文件++

说明

在Python中操纵配置文件的模块包是configparser
它一般适用的配置文件的格式是类似于MySQL的参数文件/etc/my.cnf那样的文件的。

这种配置文件中的键(Key)值(Value)一般都是文本形式的静态文件。

但更多的时候我们希望配置文件中的值是可以跟着当前所在环境而动态变化的。
并且,配置文件最好可以像Linux环境中的环境变量文件~/.bash_profile那样引用之前设置好的变量,而不是从头开始写很多冗余的内容。

因此,为了实现上述的两种基本需求,我编写了这样一个Python脚本。
configparser的基础上增加了自定义的语法支持:

  1. 在配置文件中,引用操作系统命令的执行结果为某个参数的值,使用一对【`】号,框选期望的操作系统命令;
  2. 在配置文件中,引用配置文件中定义的其他参数的值,使用一对【@】符号,并且引用参数的格式为: 参数的[section]名称.参数的key名称

具体的使用方法可以参阅下面的演示部分。

演示

配置文件

[os]
username=Leviathan·利维坦
hostname=<@os.username@>你好,欢迎来到#`hostname`#

例如,我希望从上面的配置文件中获取[os]下的hostname参数的值;

运行效果如下所示:

D:\PyCharm_data\python_config_file_plus\venv\Scripts\python.exe D:/PyCharm_data/python_config_file_plus/config_file_plus.py
===============
<Leviathan·利维坦>你好,欢迎来到#Godzilla#

Process finished with exit code 0

可以看到:

  1. 通过【@】获得了对配置文件中其他参数的引用
  2. 通过【`】获得了操作系统命令执行的结果

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

configparser_plus-0.0.8.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

configparser_plus-0.0.8-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file configparser_plus-0.0.8.tar.gz.

File metadata

  • Download URL: configparser_plus-0.0.8.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for configparser_plus-0.0.8.tar.gz
Algorithm Hash digest
SHA256 65c4cccbeb9312035d7d0391d5596e8de3af415b2f8c7527cdb75344532071e1
MD5 43e1df85cf6ed226682854d1ec3ce04f
BLAKE2b-256 81b529499c3c2a460a532fcfc1813cf7a011bde0cd85470cd71e90d76bdd8000

See more details on using hashes here.

File details

Details for the file configparser_plus-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: configparser_plus-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for configparser_plus-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2e303ed893cdf4504edfdbe690fb17e79b39e3fd8573c8f6e1952858d665669d
MD5 b1939084d614d19828c0b20dbc334a4d
BLAKE2b-256 07f08bd63c33c8672df98b5ff931ffa8bfaa01b7ea042be87a6800f2a77f6513

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