[Python] Multiple variables in a 'with' statement?

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    Is it possible to declare more than one variable using a with statement in Python?

    Something like:

    from __future__ import with_statement

    with open("out.txt","wt"), open("in.txt") as file_out, file_in:
    for line in file_in:
    file_out.write(line)


    ... or is cleaning up two resources at the same time the problem?

    Continue reading...

Compartilhe esta Página