Code Monkey home page Code Monkey logo

flexconf's Introduction

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

flexconf's People

Contributors

kattsuuya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.