新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

python将打印输出日志文件的方法-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联公司专业为企业提供海拉尔网站建设、海拉尔做网站、海拉尔网站设计、海拉尔网站制作等企业网站建设、网页设计与制作、海拉尔企业网站模板建站服务,十载海拉尔做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

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

首先导入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://www.wjwzjz.com/article/dedoei.html
在线咨询
服务热线
服务热线:028-86922220
TOP