[Python] Writing to stdout to screen AND file [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    By default, print() writes stdout and stderr to the console. If I do this:

    # Redirect stdout and stderr to a file
    log_file = open("app.log", "w")
    sys.stdout = log_file
    sys.stderr = log_file


    then print() writes stdout and stderr to 'app.log'. But is it possible to write both to the screen and to the file?

    Continue reading...

Compartilhe esta Página