redirect prints to log file

前端 未结 8 1583
萌比男神i
萌比男神i 2020-12-02 09:05

Okay. I have completed my first python program.It has around 1000 lines of code. During development I placed plenty of print statements before running a command

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 09:50

    You can create a log file and prepare it for writing. Then create a function:

    def write_log(*args):
        line = ' '.join([str(a) for a in args])
        log_file.write(line+'\n')
        print(line)
    

    and then replace your print() function name with write_log()

提交回复
热议问题