How can I write the shell output in to a text file in python? I want to save the shell output as a log in a text file and I am currently using spyder.
Asked
Active
Viewed 321 times
1 Answers
2
Instead of just using print statement or print(statement), use:
a) some logging modules. Have a look at logging
module for example.
b) an opened file for the output and write everything to that file. So in your script:
fout=open('log.txt','w')
# Here are your script things....
fout.write(statement+'\n')
# More script things ...
fout.close()
c) use an example from this post: How to save the output of an IPython console to a file in Spyder?

msi_gerva
- 2,021
- 3
- 22
- 28