上海做网站建设公司,学好网页设计与网站建设的意义,线上课程,求一个网站你知道的做python实验有时候需要打印很多信息在控制台(console#xff09;#xff0c;但是控制台的信息不方便回顾和保存#xff0c;故而可以采用logging将信息存储起来。
先新建一个文件message.log代码如下#xff1a;
import logging
logging.basicConfig(filenamemessa…做python实验有时候需要打印很多信息在控制台(console但是控制台的信息不方便回顾和保存故而可以采用logging将信息存储起来。
先新建一个文件message.log代码如下
import logging
logging.basicConfig(filenamemessage.log,levellogging.INFO,format%(message)s,filemodew)
logging.info(hello)
logging.info(hi)结果 如果不在第一步新建文件的话运行程序不会自动建立message.log文件debug程序会自动建立message.log文件。还是最开始就建立文件方便一些。
如果需要时间戳可以将第四行代码改成
format%(asctime)s %(message)s即将总体改成
import logging
logging.basicConfig(filenamemessage.log,levellogging.INFO,format%(asctime)s %(message)s,filemodew)
logging.info(hello)
logging.info(hi)结果 这样就可以将运行结果都打印到message.log上方便查看复制粘贴。