配置文件setting.ini
[app] appName = apptest Ip = 0.0.0.0 Port = 10010
读取方法:
import ConfigParser
from log4py import log4py
var = {}
log=log4py("readConfig.py")
def getConfig(configFile):
try:
cf = ConfigParser.ConfigParser()
cf.read(configFile)
except Exception,e:
log.error(e)
traceback.print_exc()
for section in cf.sections():
for key,values in cf.items(section):
log.debug("Config:"+key+":"+values)
var[key] = values
getConfig(‘setting.ini‘)
print var[‘port‘]本文出自 “自动化rolin” 博客,请务必保留此出处http://luoguoling.blog.51cto.com/1568501/1945079
原文地址:http://luoguoling.blog.51cto.com/1568501/1945079