【问题标题】:Writing to a file when python printspython打印时写入文件
【发布时间】:2017-08-18 19:41:43
【问题描述】:

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

例如:

This is being printed to the console

And I want it to do this

【问题讨论】:

    标签: python-3.x discord


    【解决方案1】:

    你可以做这个链接

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 2011-05-04
      • 2012-03-08
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      相关资源
      最近更新 更多