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 flexconf 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.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

flexconf-1.0.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file flexconf-1.0.4.tar.gz.

File metadata

  • Download URL: flexconf-1.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for flexconf-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d6fd572e57b25b08f04a48f16d3802ed819b67f29ecdedc8a9b45695ac52e4ce
MD5 f2d9b5cb35252566ddaf8e6d94009a1b
BLAKE2b-256 c3d7eb40e30d22dbff671e5981c937ebd356015a217e03707caedf664f474381

See more details on using hashes here.

File details

Details for the file flexconf-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: flexconf-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for flexconf-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e5784db5cc17652304e8615c012d4e55d6e8fcb1dad1e46af4dfbac435ddadbd
MD5 4c888ab0572566874914b4952727b721
BLAKE2b-256 4cba3dcb695f8e9655cbd9049415b2559bc3169b1b36f8bcc95d3128fe05cf73

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