快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

python将打印输出日志文件的方法

这篇文章主要介绍python将打印输出日志文件的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

成都创新互联是一家专业提供泰宁企业网站建设,专注与网站设计、做网站、H5技术、小程序制作等业务。10年已为泰宁众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。

首先导入sys模块,然后利用sys.stdout将print行导向到你定义的日志文件中,例如:

import sys
# make a copy of original stdout route
stdout_backup = sys.stdout
# define the log file that receives your log info
log_file = open("message.log", "w")
# redirect print output to log file
sys.stdout = log_file
print "Now all print info will be written to message.log"
# any command line that you will execute
...
log_file.close()
# restore the output to initial pattern
sys.stdout = stdout_backup
print "Now this will be presented on screen"

以上是python将打印输出日志文件的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


网页名称:python将打印输出日志文件的方法
转载注明:http://6mz.cn/article/jdjied.html

其他资讯