|
Project Information
Featured
Downloads
|
Introductionconfigpy lets you read config files with ease in Python. See the below for examples of the power of this module. ExamplesSimple Variablesfrom configpy import Config cfg = """ first_name="Foo" """ config = Config(cfg) print config.first_name # "prints Foo" Compound Variablesconfigpy support look-behind and look-ahead variables. from configpy import Config
cfg = """
last_name="${temp}"
first_name="Foo"
temp="Bar"
full_name="${last_name}, ${first_name}"
"""
config = Config(cfg)
print config.full_name # prints "Bar, Foo"Type Awareconfigpy supports list, dict, float, int and string types. from configpy import Config
cfg = """
nums = [1,2,3,4]
nando = "Nando"
names = ["Stevie", "${nando}", "Robbie"]
planets = { 'planet': '${red_planet}' }
red_planet = 'mars'
num_items = 5
item_cost = 1.99
"""
config = Config(cfg)
print sum(config.nums) # prints 10
print config.planets['planet'] # prints "mars"
config.names.sort()
print config.names # prints ["Nando", "Robbie", "Stevie"]
print config.num_items * config.item_cost # prints 9.95See the test file for more examples. |