How to save python screen output to a text file

前端 未结 10 1027
星月不相逢
星月不相逢 2020-12-08 06:16

I\'m new to Python. I need to query items from a dict and save the result to a text file. Here\'s what I have:

import json
import exec.fullog as e

input = e         


        
10条回答
  •  臣服心动
    2020-12-08 06:32

    You would probably want this. Simplest solution would be

    Create file first.

    open file via

    f = open('', 'w')
    

    or

    f = open('', 'a')
    

    in case you want to append to file

    Now, write to the same file via

    f.write()
    

    Close the file after you are done using it

    #good pracitice
    f.close()
    

提交回复
热议问题