I can print Python statements to output (in one script) but I'm getting confused with imported modules, functions, and main(). I'm doing like this:
import sys
old_stdout = sys.stdout
log_file = open("message.log","w")
sys.stdout = log_file
print("something")
sys.stdout = old_stdout
log_file.close()
In the code base I'm working on, it's like
import classes from other .py scripts
def some_big_function()
# the code from above to print to output
def main():
# a few print statements
some_big_function(args)
main()
How do I get all print statements to go to one file? I put print statements in some_big_function() and it seems to work.
But what if I have print statements in main()? They won't print to output like in some_big_function().