Change the standard output destination to a file in Python

Example

How to change to a file named log.out

fo = open('log.out', 'w')
sys.stdout = fo

Recommended Posts

Change the standard output destination to a file in Python
Write standard output to a file
Output timing is incorrect when standard (error) output is converted to a file in Python
[python] Change the image file name to a serial number
Output the key list included in S3 Bucket to a file
Read the standard output of a subprocess line by line in Python
How to create a JSON file in Python
Output in the form of a python array
How to output "Ketsumaimo" as standard output in Python
I made a program to check the size of a file in Python
Download the file in Python
A memorandum to run a python script in a bat file
I want to randomly sample a file in Python
[Python] Change standard input from keyboard to text file
[Work efficiency] How to change file names in Python
Output a binary dump in binary and revert to a binary file
[Python] How to output the list values in order
Various ways to read the last line of a csv file in Python
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
Run the output code with tkinter, saying "A, pretending to be B" in python
Output "Draw ferns programmatically" to the drawing process in Python
How to debug the Python standard library in Visual Studio
How to use the __call__ method in a Python class
Output to csv file with Python
[Python] Change the text color and background color of a specific keyword in print output
How to import a file anywhere you like in Python
In the python command python points to python3.8
Make standard output non-blocking in Python
Create a binary file in Python
A standard way to develop and distribute packages in Python
[Note] Import of a file in the parent directory in Python
How to get the last (last) value in a list in Python
[Selenium] Change log output destination when executing phantomjs in python3
Output the specified table of Oracle database in Python to Excel for each file
[Mac] A super-easy way to execute system commands in Python and output the results
[Python] How to change EXCEL file saved in xlsb to xlsx
[Python] How to output a pandas table to an excel file
[Python] Change the alphabet to numbers
What seems to be a template of the standard input part of the competition pro in python3
Convert to a string while outputting standard output with Python subprocess
How to determine the existence of a selenium element in Python
[Introduction to Python] How to output a character string in a Print statement
How to check the memory size of a variable in Python
Create a shell script to run the python file multiple times
Output the contents of ~ .xlsx in the folder to HTML with Python
Feel free to change the label of the legend in Seaborn in python
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
How to output the output result of the Linux man command to a file
Read a file in Python with a relative path from the program
Change the active version in Pyenv from anaconda to plain Python
Get the formula in an excel file as a string in Python
Write the test in a python docstring
Convert psd file to png in Python
Change the list in a for statement
Run the Python interpreter in a script
How to get a stacktrace in python
Read the file line by line in Python
Read the file line by line in Python
[GPS] Create a kml file in Python
[Python] Read the specified line in the file