How to execute a python script and write output to txt file?

后端 未结 8 600
离开以前
离开以前 2020-12-10 14:31

I\'m executing a .py file, which spits out a give string. This command works fine

execfile (\'file.py\')

But I want the output (in addition to it being shown

8条回答
  •  春和景丽
    2020-12-10 15:11

    If you are running the file on Windows command prompt:

    python filename.py >> textfile.txt
    

    The output would be redirected to the textfile.txt in the same folder where the filename.py file is stored.

    The above is only if you have the results showing on cmd and you want to see the entire result without it being truncated.

提交回复
热议问题