Skip to content

Instantly share code, notes, and snippets.

@travisbhartwell
Forked from goozbach/foo.ini
Created October 26, 2009 00:57
Show Gist options
  • Save travisbhartwell/218351 to your computer and use it in GitHub Desktop.
Save travisbhartwell/218351 to your computer and use it in GitHub Desktop.
# this is a comment
[default]
foo = yes
bar = no
cam = maybe
var = 23
prefix = /var/lib/
dir = %(prefix)s/bar/
#!/usr/bin/python
import ConfigParser
import os
import sys
config = ConfigParser.ConfigParser()
_execdir = os.path.dirname(sys.argv[0])
_configfile = os.path.join(_execdir,'foo.ini')
config.read(_configfile)
print _configfile
# print out a var from config
print config.get('default', 'foo', 0) # -> "Python is fun!"
# set the configs into global vars
for foo in config.items('default'):
item, value = foo
globals()[item] = value
print "globals"
# dir should come from the config file
print dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment