Skip to main content

Flexible Configure

Project description

FlexConf

Flexible Configure

Installation

pip install flexconf

プロジェクト配下で以下のコマンドを実行すると、設定ファイルのテンプレートが作成されます。

python -m flexconf

Examples

例えば以下の構成を考える。

.
├─ .flexconf/
│   ├─ pattern1.conf
│   └─ pattern2.conf
└─ sample.py         # ライブラリを使用するスクリプト

それぞれの設定ファイルは以下のような構成にする。

# pattern1.conf
[DEFAULT]           # 必ず書く
A = 3               # パラメータ名 = 値 という書式で記述する
B = 1920 1080       # 値にものが文字列として読み込まれる

この設定を利用するサンプルプログラム

# sample.py
from myutils import FlexConf

class SubClass(FlexConf):
    # __init__を定義する必要はない
    # 定義する場合は、super().__init__()を実行する
    def __init__(self):
        # do something here
        super().__init__()

    def sample_method(self):
        # `./.flexconf/*.conf`に定義したパラメータの値を
        # self.パラメータ名 で取得することができる
        print(self.A)
        print(self.B)

if __name__ == "__main__":
    s = SubClass()
    s.sample_method()

実行例

// -p オプションで使用したい設定ファイルを選択する
$ python sample.py -p pattern1
3
1920 1080
$ python sample.py -p pattern2
4
hogehoge

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

flexconf-1.0.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

flexconf-1.0.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

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