Code
[url]
baidu = http://www.baidu.com
[value]
send_value = 百度
[server]
ip = 220.181.111.188
封装的格式可以套用
# 封装,类似函数调用
import configparser
class ReadConfigIni():
def __init__(self,filename):
self.cf = configparser.ConfigParser()
self.cf.read(filename)
def getConfigValue(self,section,name):
value = self.cf.get(section,name)
# print(value)
return value
DoConfigIni = ReadConfigIni("test.ini") #路径+文件名
BaiUrl = DoConfigIni.getConfigValue("url","baidu")
print("通过函数getConfigValue获得的值:",BaiUrl)