Giter VIP home page Giter VIP logo

pylibconfig2's Introduction

pylibconfig2

Pure python library for libconfig syntax. IO works via strings, and include directives.

Usage

Scalar types are pythons basic types str, int, long, float, bool. The libconfig types Array, List, Group are implemented as ConfArray, ConfList, ConfGroup, respectively. A config is setup from a string only, and represented as a string automatically.

The config

Config represents a libconfig configuration. The string representation is itself readable as a config. Access works via attributes:

>>> import pylibconfig2 as cfg
>>> c = cfg.Config("my_setting = 5;")
>>> str(c)
'my_setting = 5;'
>>> c.my_setting
5

Or via lookup as in the original libconfig way (no exceptions are raised):

>>> c = Config('my = {nested = {sett = (0, {ng = "rocks!"})}}')
>>> c.lookup('my.nested.sett.[1].ng')
'rocks!'
>>> c.lookup('my.nested.foo', 'bar')
'bar'
Setting values should be done by path (but attribution is also possible):
>>> c = Config('')
>>> c.setup('foo', 1)
True
>>> c.setup('bar', '{hello = "world"}')
True
>>> c.lookup('bar.hello')
'world'
>>> c.setup('a.nonexisting.group', '"returns False!"')
False

These functions are given for further convenience:

keys() values() items() get(key, default) set(key, value)

An array

ConfArray represents a libconfig array. Access works via the [] operator:

>>> c = cfg.Config("my_array = [1, 2, 3];")
>>> c.my_array[1]
2

A list

ConfList represents a libconfig list. Access works via the [] operator:

>>> c = cfg.Config('my_list = (1.5, 2L, 0xee, "string");')
>>> c.my_list[1]
2L

A group

ConfGroup represents a libconfig group. Access works via attributes:

>>> c = cfg.Config("my_group = {my_setting = 5;};")
>>> c.my_group.my_setting
5

Again, these functions are given for convenience:

keys() values() items() get(key, default) set(key, value)

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.