tr11 / python-configuration

A Python library to load configuration parameters

Home Page:https://tr11.github.io/python-configuration/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Dot notation in py configuration

chinghwayu opened this issue · comments

Can dots be enabled as a separator in python configuration files? That seems more intuitive that specifying _ or __.

Doesn't this work already as is?

I'd like to be able to specify conf.py as:

a.b = 3

Then load:

cfg = config_from_python(
    ["conf.py"], prefix="", separator=".", lowercase_keys=True
)

a.b would expand to {"a": {"b": 3}}
Is this possible?

Not sure how without creating object a and setting its members; a.b = 3 won't be valid without a defined. Are you planning on defining a as some sort of attribute-enabled dict or something like that?

ack... yes, I should've added that detail. How could I import in an attribute-enabled dict in config?

I think I figured it out...

from config.helpers import AttributeDict
a = AttributeDict()
a.b = 3
del AttributeDict

Yeah, that's what I meant. I think this is an import use case; I'll add it as an example to the docs and maybe promote the AttributeDict class to the config module (instead of the helpers).

I noticed that the AttributeDict class doesn't allow for nesting of more than 1 level. For example, you can't do something such as:

from config.helpers import AttributeDict
a = AttributeDict()
a.b.c = 3
del AttributeDict

For that, the user would need to use something like python-box. Not sure if you want to implement that but may be worth noting in the docs.