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

后端 未结 8 594
离开以前
离开以前 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:21

    The simplest way to run a script and get the output to a text file is by typing the below in the terminal:

    PCname:~/Path/WorkFolderName$ python scriptname.py>output.txt

    *Make sure you have created output.txt in the work folder before executing the command.

提交回复
热议问题