ConfigParser处理配置文件挺方便的。
- 配置文件读取
代码块
conf = ConfigParser.ConfigParser()
conf.read('.\ssl.cfg')
strs = conf.get('DATA','hello')
配置文件示例:
[DATA]
hello=what?
- 写配置文件
import ConfigParser
def wConfig(filename):
config = ConfigParser.ConfigParser()
config.add_section("HW")
config.set('HW','hello','100')
config.write(open(filename, 'a'))
wConfig('.\\vs.cfg')