[core]
cmd = /usr/bin/vim
[mod]
safe_edit = yes
time_interval = 20
python 程式如下:
#!/usr/bin/python
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('test.conf')
#傳回字串 /usr/bin/vim
parser.get('core', 'cmd')
#傳回 boolean 值 True
parser.getboolean('mod', 'safe_edit')
#傳回整數值 20
parser.getint('mod', 'time_interval')
references:
http://williewu.blogspot.tw/2007/10/python-configparser.html
https://wiki.python.org/moin/ConfigParserExamples
https://docs.python.org/2.6/library/configparser.html