Skip to content

Instantly share code, notes, and snippets.

@pdxjohnny
Created May 11, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxjohnny/dbb432c08795d6322090 to your computer and use it in GitHub Desktop.
Save pdxjohnny/dbb432c08795d6322090 to your computer and use it in GitHub Desktop.
Grabs config sections as dicts
"""
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