아미(아름다운미소)

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

랭귀지/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

'랭귀지 > PYTHON' 카테고리의 다른 글

python for in list  (0) 2019.04.05
python filter  (0) 2019.04.03
[PYTHON] MULTIPART FILE UPLOAD  (0) 2019.03.29
Consider using the `--user` option or check the permissions.  (0) 2019.03.25
Python3 내장 자료형  (0) 2019.03.05
Comments