Be myself :: with~as 구문

달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

with~as 구문

Python 2015. 2. 22. 13:13

파일 관련 코딩을 할 때 open 으로 파일 객체를 생성하고 close를 해 주는데 이 과정을 편리하게 다음과 같이 할 수 있다.

with open("test.txt","w") as f:
    f.write("this is test")

저렇게만 해도 close과정은 자동으로 된다.

'Python' 카테고리의 다른 글

os.execve 주의  (0) 2015.03.31
str과 repr의 차이  (0) 2015.02.22
개발 시 팁  (0) 2015.02.18
string처리, 관련 메소드  (0) 2014.10.01
struct 관련  (0) 2014.09.18
Posted by flack3r
|