How can I open multiple files using “with open” in Python?

后端 未结 7 920
天涯浪人
天涯浪人 2020-11-22 08:15

I want to change a couple of files at one time, iff I can write to all of them. I\'m wondering if I somehow can combine the multiple open calls with the

7条回答
  •  时光取名叫无心
    2020-11-22 09:13

    With python 2.6 It will not work, we have to use below way to open multiple files:

    with open('a', 'w') as a:
        with open('b', 'w') as b:
    

提交回复
热议问题