I have this piece of code:
class Logger(object):
def __init__(self):
self.terminal = sys.stdout
self.log = open("filee.txt", "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
pass
sys.stdout = Logger()
print("Hello")
input("How are you today? ")
print("That's nice to hear!")
I want my output to both console and file be the following:
Hello
How are you today? "something that user enters"
That's nice to hear!
When I use mentioned piece of code only things inside of print() and before input() are printed out well. I want to point out that this piece of code works fine when I work ONLY with print() statement but I want everything related to input too be displayed properly. So, I wonder if anyone knows is there a way to achieve that functionality and what would it be?