在python打印时写入文件(Writing to a file when python prints)

编程入门 行业动态 更新时间:2024-10-22 15:22:47
在python打印时写入文件(Writing to a file when python prints)

我正在制作一个带有discord.py的机器人,并且需要一个日志记录系统,我的机器人已经将错误输出到一个日志文件中,但是我希望它将任何打印到控制台的东西输出到文本文件中。

例如:

这将被打印到控制台

我希望它能做到这一点

I'm making a bot with discord.py and need a logging system, my bot already outputs errors to a log file, however I would like it to output anything printed to console into a text file.

E.g:

This is being printed to the console

And I want it to do this

最满意答案

你可以做这个链接

with open("file","a") as f: #place all your codes in this block print("hello",file=f)

You can do this link

with open("file","a") as f: #place all your codes in this block print("hello",file=f)

更多推荐

本文发布于:2023-08-04 22:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1424520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   python   Writing   prints   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!