Created
May 11, 2015 15:49
-
-
Save pdxjohnny/dbb432c08795d6322090 to your computer and use it in GitHub Desktop.
Grabs config sections as dicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
config.py | |
John Andersen | |
johnandersenpdx@gmail.com | |
This file provides quick access to sections | |
of a config file by use of ConfigParser. | |
""" | |
import os | |
import ConfigParser | |
import copy | |
def str2bool(variable): | |
""" | |
Tests whether a variable would equate to True | |
""" | |
return str(variable).lower() in ("yes", "true", "t", "1", "on") | |
def config(file_name = 'config.txt'): | |
""" | |
Reads the config file and returns config object | |
""" | |
config_txt = ConfigParser.ConfigParser() | |
config_txt.read(file_name) | |
return config_txt | |
def section(name): | |
""" | |
Returns the section of the config file as a dict | |
""" | |
items = {} | |
all_items = config().items(name) | |
for item in all_items: | |
items[item[0]] = item[1] | |
return items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment