Python으로 함수 작성하기
Shayne Miel
Software Architect @ Duo Security
컨텍스트 매니저는:





컨텍스트 매니저:
케이터링 직원:
with open('my_file.txt') as my_file:
text = my_file.read()
length = len(text)
print('The file is {} characters long'.format(length))
open()은 세 가지를 수행합니다:
with
with <context-manager>()
with <context-manager>(<args>)
with <context-manager>(<args>):
with <context-manager>(<args>):
# 여기서 코드를 실행합니다
# 이 코드는 "컨텍스트 내부"에서 실행됩니다
with <context-manager>(<args>):
# 여기서 코드를 실행합니다
# 이 코드는 "컨텍스트 내부"에서 실행됩니다
# 이 코드는 컨텍스트 해제 후 실행됩니다
with <context-manager>(<args>) as <variable-name>:
# 여기서 코드를 실행합니다
# 이 코드는 "컨텍스트 내부"에서 실행됩니다
# 이 코드는 컨텍스트 해제 후 실행됩니다
with open('my_file.txt') as my_file:
text = my_file.read()
length = len(text)
print('The file is {} characters long'.format(length))
Python으로 함수 작성하기