在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)更多推荐
发布评论