I am using the below statements to redirect the output of python program to a log_file and it works.
import sys
sys.stdout = open(log_file, 'a', buffering=1)
But, I would like to pass one or two specific print statements to another flat file(let's suppose sample_file.txt). How can I do that ?
append modeand write your data in it:with open("sample_file.txt", "a") as f: f.write("hello world!\n")loggingmodule in your project.