十五.配置和日志

1.配置

#config.ini的内容如下
[numbers]
pi:3.141592653
e:2.718281828
[messages]
head:This is head text!
result:This is result text!

#配置模块configparser
import configparser
File="config.ini"
config=configparser.ConfigParser()
#读取配置文件
config.read(File)
print(config["numbers"].get("pi"))
print(dict(config["numbers"]))

 

 

2.日志

import logging
logging.basicConfig(level=logging.INFO,filename="mylog.log")
logging.info("Start")
logging.info("Try to divide 1 by 0")
print(1/0)
logging.info("OK")

 

posted @ 2019-04-10 22:25  观井映天  阅读(93)  评论(0编辑  收藏  举报