688 바이트 추가됨
, 2021년 11월 24일 (수) 20:31
== 개요 ==
파일을 사용할 때 특정 객체를 사용하여 <code>객체=open(....)</code> 형태의 문장을 사용해 열고, <code>객체.close()</code> 형태의 문장을 사용해 파일을 닫는다. 이를 간략화 하고 직관적으로 사용하기 위한 구문.
== 어떻게 간략화 되는가? ==
{| class="wikitable"
|+
!기본 사용
!with 구문 사용
|-
|<syntaxhighlight lang="python">
f = open("file.txt","w")
f.write("작성할 메시지")
f.close()
</syntaxhighlight>
|<syntaxhighlight lang="python">
with open("file.txt","w") as f:
f.write("작성할 메시지")
</syntaxhighlight>with 구문을 나오면 자동으로 닫힌다.
|}
[[분류:기초]]