cashflower icon indicating copy to clipboard operation
cashflower copied to clipboard

Logging with redirection

Open zchmielewska opened this issue 2 years ago • 0 comments

You can redirect prints from terminal to the external text file.

Something like that:

import os
import sys

# Open a file
file = open("output.txt", "w")

# Get the file descriptor
fd = file.fileno()

# Duplicate the file descriptor to the standard output
os.dup2(fd, sys.stdout.fileno())

# Now any print statement will write to the file
print("This message will be written to the file")

# Close the file
file.close()

Perhaps it can be useful for debugging.

zchmielewska avatar Mar 14 '24 10:03 zchmielewska