Skip to content

Instantly share code, notes, and snippets.

@jimallman
Created July 16, 2015 15:35
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 jimallman/fa79cddd3a0a0fa4733f to your computer and use it in GitHub Desktop.
Save jimallman/fa79cddd3a0a0fa4733f to your computer and use it in GitHub Desktop.
Quick test of local config file (for web-app configuration, etc)
# A quick validator for web-app config files
import os
from ConfigParser import SafeConfigParser
conf = SafeConfigParser({})
if not os.path.isfile("./config"):
print("Expecting a file 'config' in the current directory")
exit()
conf.read("./config")
try:
conf.read("./config")
except:
print("Found a local 'config' file, but I can't read it!")
exit()
print("\n\nSections in this config file:")
for sec in conf.sections():
print(" {}".format(sec))
print("\n\nOptions within each section:")
for sec in conf.sections():
print(" [{}]".format(sec))
for opt in conf.options(sec):
print(" {o} = {v}".format(o=opt, v=conf.get(sec,opt)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment