Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将shell输出写入文本文件_Python_Shell - Fatal编程技术网

Python 将shell输出写入文本文件

Python 将shell输出写入文本文件,python,shell,Python,Shell,如何用python将shell输出写入文本文件?我想将shell输出保存为文本文件中的日志,目前正在使用spyder。使用以下命令,而不仅仅是使用print语句或printstatement: 一些日志模块。以日志模块为例 b为输出打开一个文件,并将所有内容写入该文件。因此,在您的脚本中: fout=open('log.txt','w') # Here are your script things.... fout.write(statement+'\n') # More script thin

如何用python将shell输出写入文本文件?我想将shell输出保存为文本文件中的日志,目前正在使用spyder。

使用以下命令,而不仅仅是使用print语句或printstatement:

一些日志模块。以日志模块为例

b为输出打开一个文件,并将所有内容写入该文件。因此,在您的脚本中:

fout=open('log.txt','w')
# Here are your script things....
fout.write(statement+'\n')
# More script things ...
fout.close()
c使用本文中的示例: