首页 > 编程语言 > 详细

python 读取配置文件的值

时间:2015-03-16 12:59:06      阅读:266      评论:0      收藏:0      [点我收藏+]

上例子:

假设配置文件如下,文件名为test.cfg

#------------------------------------

#abcdefg

abc = 1

#-----------------------------------------

其中的#号后面的部分都是注释


读入该文件的python代码为:

from types import ModuleType
import re
cfg = []
fcfg = "D:/test.cfg"
content = {}
try:
	execfile(fcfg, context)
except Exception,e:
	......

for k,v in  content:
	if re.serch('^_',k) == None and not type(v) is ModuleType:
		cfg[k] = v

这样就完成解析

使用方法为: cfg[‘abc‘]

python 读取配置文件的值

原文:http://blog.csdn.net/u010640235/article/details/44302591

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!