Package: ezcf
ezcf====|Build Status| |Supported Python versions| |PyPI version| |CoverageStatus|ezcf stands for **easy configuration**, it allows you to importJSON/YAML/INI/XML like .py files. It is useful whenever you need to readfrom these formats, especially for reading configuration files.OK, stop talking, show us some code!On the left is what you'll normally do, on the right is the ezcf way.**All you need is ``import ezcf`` first, then ``import filename``without extension.** Nothing else!.. figure:: https://github.com/laike9m/ezcf/raw/master/code_compare.png:alt:For instance, here we want to load file ``config.json``. With a singleline of code ``from config import *``, everything is done and you'rehappy.Install-------::pip install ezcfIf you run into ``error: yaml.h: No such file or directory``, don'tworry, you can still use ezcf without any problem.Supported File Types--------------------ezcf supports ``JSON``, ``YAML``, ``INI`` and ``XML`` with extension``json``, ``yaml``, ``yml``, ``ini``, ``xml``.Sample Usage------------Let's start with an easy case:::├── sample1.py└── sample1.json``sample1.py`` and ``sample1.json`` are in the same directory. We wantto read ``sample1.json`` in ``sample1.py``, here's how:.. code:: python"""# sample1.json{"hello": "world"}"""# sample1.pyimport ezcffrom sample1 import helloprint(hello)  # 'world'It's that easy.That's cool, but we usually put config files in a separate folder. Canezcf deal with that?::├── conf│   ├── __init__.py│   └── sample2.yaml└── sample2.pyWhy not?.. code:: python"""sample2.yaml---Time: 2001-11-23 15:02:31 -5User: edwarning:This is a warning.---Stack:- file: TopClass.pyline: 23code: |x = MoreObject("345\n")- file: MoreClass.pyline: 58code: |-foo = bar"""# sample2.pyimport ezcffrom conf.sample2 import Time, User, warning, StackTime  # datetime.datetime(2001, 11, 23, 20, 2, 31)User  # edwarning  # This is a warning.Stack  # [{'line': 23, 'code': 'x = MoreObject("345\\n")\n', 'file': 'TopClass.py'}, {'line': 58, 'code': 'foo = bar', 'file': 'MoreClass.py'}]ezcf supports all kinds of valid import statements. These statements areequivalent:.. code:: pythonfrom conf.sample2 import Time, User, warning, Stackfrom conf.sample2 import *import conf.sample2  # then use conf.sample2.Time/User/warning/Stackimport conf.sample2 as cs  # then use cs.Time/User/warning/StackIn a word, you can assume they're just regular python files.(Currentlyezcf only supports files with utf-8 encoding)What about relative import? Yes, ezcf supports relative import, as longas you use it *correctly*.Note----1. Be careful importing YAML which contains multiple documents: if thereexists keys with the same name, only one of them will be loaded. Soit's better not to use multiple documents;2. All values in ``.ini`` files are kept as it is and loaded as astring;3. Since XML only allows single root, the whole xml will be loaded asone dict with root's name as variable name;4. Use `**valid variablenames** <https://docs.python.org/3.4/reference/lexical_analysis.html#identifiers>`__,this means key strings in JSON/YAML/INI/XML should be valid Pythonvariable name. Invalid variable name won't do any harm to yourprogram nor will it crash, but you can't use them as expected.Run Tests---------::python setup.py testRoadmap--------  [x] Use dot to seperate folder/subfolder/file-  [x] Unicode support-  [x] JSON support-  [x] YAML support-  [x] INI support-  [x] XML support-  [ ] Auto encoding detect?-  [x] CI-  [x] coverage-  [x] pypiLicense-------MIT.. |Build Status| image:: https://travis-ci.org/laike9m/ezcf.svg:target: https://travis-ci.org/laike9m/ezcf.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/ezcf.svg:target: https://pypi.python.org/pypi/ezcf/.. |PyPI version| image:: https://badge.fury.io/py/ezcf.svg:target: http://badge.fury.io/py/ezcf.. |Coverage Status| image:: https://coveralls.io/repos/laike9m/ezcf/badge.svg:target: https://coveralls.io/r/laike9m/ezcf