DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+4 votes

This is what I'm doing

with open("fileA", "r") as A:
    with open("fileB", "r") as B:
        with open("fileC", "w") as C:
            # Read from A, B, and write to C
            ...

Is there a more pythonic way for opening multiple files at once without all the indentation?

by

1 Answer

+2 votes
 
Best answer
with open("file A", "r") as A, open("fileB", "r") as B, open("fileC", "w") as C:
    ....

Actually had to check the exact syntax on this StackOverflow post, credit is due.

by
selected by
Contributions licensed under CC0
...