랭귀지/python

python with open을 써서 파일을 여러 개 open하는 법

유키공 2019. 4. 2. 12:23

with open을 써서 파일을 여러 개 open하는 법

with문을 써서 한 줄에 여러 개 파일을 열고 싶을때

try:
  with open('a', 'w') as a, open('b', 'w') as b:
    do_something()
except IOError as e:
  print 'Operation failed: %s' % e.strerror