Skip to content

Instantly share code, notes, and snippets.

@mpurzynski
Created December 23, 2015 00:50
Show Gist options
  • Save mpurzynski/a9ab25218dad4fe57779 to your computer and use it in GitHub Desktop.
Save mpurzynski/a9ab25218dad4fe57779 to your computer and use it in GitHub Desktop.
import os
import sys
import ConfigParser
configfile = './example.conf'
try:
if os.path.exists(configfile):
Config = ConfigParser.ConfigParser()
Config.read(configfile)
sections = Config.sections()
for section in sections:
if section is not None:
print(section)
options = Config.options(section)
for option in options:
if option is not None:
print(option, Config.get(section, option))
except Exception as e:
sys.stderr.write('Something is seriously fucked up, python thrown up and the exception is: {0}\n'.format(e))
sys.stderr.write('Fix your config file. Or your script. Or your libs. Have a nice day. Your beloved script.\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment