新建配置文件config_test.conf 配置文件目录C:\Users\Administrator\Desktop\test\conf
[option]
1=zhangsan
2=lisi
3=wangwu
import ConfigParser
def get_config_name():
config_path = r'C:\Users\Administrator\Desktop\test\conf\config_test.conf'
config = ConfigParser.ConfigParser()
config.read(config_path)
print config.get("option", 3)
print config.get("option", 2)
if __name__ == '__main__':
try:
print 'start*****__main__*****'
get_config_name()
except KeyboardInterrupt:
sys.stderr.write("User interrupt me! ;-) Bye!\n")
sys.exit(0)
输出结果: wangwu lisi
|