4 ms·
This is an often overlooked feature of context managers; to clarify, this is a perfectly normal example: with open("foo.txt") as foo_file, open("bar.txt")
by BerislavLopac 6y ago
This is an often overlooked feature of context managers; to clarify, this is a perfectly normal example:
with open("foo.txt") as foo_file, open("bar.txt") as bar_file, open("baz.txt", "w") as baz_file:
baz_file.write(foo_file.read() + bar_file.read())
- lunixbochs 6y agoI think you can also do something like this if you want it to be readable with (open("foo.txt") as foo_file, open("bar.txt") as bar_file, open("baz.txt", "w") as baz_file): baz_file.write(foo_file.read() + bar_file.read())