Nafai77 (owner)

Fork Of

gist: 218348 by goozbach python-configparser

Revisions

gist: 218351 Download_button fork
public
Public Clone URL: git://gist.github.com/218351.git
Embed All Files: show embed
foo.ini #
1
2
3
4
5
6
7
8
9
# this is a comment
[default]
foo = yes
bar = no
cam = maybe
var = 23
prefix = /var/lib/
dir = %(prefix)s/bar/
 
get.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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