4 ms·
You can do multiple in a single with statement these days.
by lunixbochs 6y ago
You can do multiple in a single with statement these days.
- BerislavLopac 6y agoThis 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())