Was trying to write a command that puts anything printed to the console into a log file for later observation (but ended up finding this online anyway)
as shown in my example below, is there any way to have message_to_print defined as any number of arguments given, and for example, log_file to only accept a command if it ends in ".txt"?
i know i could just make every print command use fstrings, but that would involve reformatting like 50 print commands, which i could do, but this answer seems both good to know and is something ive wondered for a bit. i know *args exists but im unsure how to apply it, if thats the answer
def ConsolePrint(message_to_print, log_file='ConsoleOutput.txt'):
print(message_to_print)
with open(log_file, 'a') as of:
of.write('\n' + message_to_print)
ConsolePrint("This is Part 1", "and this is Part 2,", "and this is part 3.", "TestOutput.txt")```
^Currently the `ConsolePrint` command thinks "and this is part 2," is the logfile, and everything else is considered nonsense