{"id":1403,"date":"2013-11-24T15:00:01","date_gmt":"2013-11-24T15:00:01","guid":{"rendered":"http:\/\/brain.payzip.co.kr\/?p=1403"},"modified":"2013-11-24T15:00:01","modified_gmt":"2013-11-24T15:00:01","slug":"%ed%8c%8c%ec%9d%b4%ec%8d%acpython%ec%9d%98-with-as-%eb%ac%b8","status":"publish","type":"post","link":"https:\/\/blog.goorigo.com\/?p=1403","title":{"rendered":"\ud30c\uc774\uc36c(Python)\uc758 with &#8230; as \ubb38"},"content":{"rendered":"<hr \/>\n<div>\n<p>with \uad6c\ubb38\uc740 \ud30c\uc774\uc120 2.5\uc5d0\uc11c \ub3c4\uc785\ub41c \uae30\ub2a5\uc73c\ub85c \uc5b4\ub5a4 \ube14\ub7ed\uc5d0 \uc9c4\uc785\ud558\uace0 \ub098\uc62c \ub54c \uc9c0\uc815\ub41c \uac1d\uccb4(context manager)\ub85c \ud558\uc5ec\uae08 \uadf8 \uc2dc\uc791\uacfc \ub05d\uc5d0\uc11c \uc5b4\ub5a4 \ucc98\ub9ac\ub97c \ud558\ub3c4\ub85d \ud560 \ub54c \uc0ac\uc6a9\ud55c\ub2e4.<\/p>\n<pre>with A:\n    pass<\/pre>\n<p>\uc704 \ucf54\ub4dc\uc5d0\uc11c A\ub294 with \ube14\ub7ed\uc774 \uc2dc\uc791\ub418\ub294 \uc2dc\uc810\uc5d0 A.<strong>enter<\/strong>()\ub97c \ud638\ucd9c\ud558\uace0, \ube14\ub7ed\uc774 \ub05d\ub098\ub294 \uc2dc\uc810\uc5d0 A.<strong>exit<\/strong>()\ub97c \ud638\ucd9c\ud55c\ub2e4. \ub9cc\uc57d \ube14\ub7ed \ub0b4\uc5d0\uc11c \uc608\uc678\uac00 \ubc1c\uc0dd\ud558\uc5ec \ube14\ub7ed\uc758 \uc2e4\ud589\uc774 \uc911\uc9c0\ub418\uace0 \ube60\uc838\ub098\uc624\ub294 \uc2dc\uc810\uc5d0\ub3c4 A.<strong>exit<\/strong>()\uac00 \ud638\ucd9c\ub418\ub294 \uac83\uc774 \ubcf4\uc7a5\ub41c\ub2e4.<\/p>\n<p>\uc608\ub97c \ub4e4\uc5b4 \ud30c\uc77c\uc744 \uc5f4\uc5b4\uc11c \uc5b4\ub5a4 \ub0b4\uc6a9\uc744 \ucc98\ub9ac\ud558\uace0 \ud30c\uc77c\uc744 \ub2eb\ub294 \ub3d9\uc791\uc744 \uc218\ud589\ud560 \ub54c, \ucee8\ud14d\uc2a4\ud2b8 \ub9e4\ub2c8\uc800\uac00 \ud30c\uc77c\uc744 \uc5f4\uace0, \ub2eb\ub294 \ub3d9\uc791\uc744 \uc815\uc758\ud55c\ub2e4\uba74, with \uad6c\ubb38\uc5d0\uc11c\ub294 \uc774\ub97c \ucee8\ud14d\uc2a4\ud2b8 \ub9e4\ub2c8\uc800(\uc774 \uacbd\uc6b0\uc5d0\ub294 \ud30c\uc77c \ub514\uc2a4\ud06c\ub9bd\ud130)\uc5d0\uac8c \uc774\ub7ec\ud55c \ub3d9\uc791\uc744 \uc704\uc784\ud558\uace0 \uc2e4\uc81c \ub370\uc774\ud130\ub97c \ucc98\ub9ac\ud558\ub294 \ucf54\ub4dc\ub9cc \uc791\uc131\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre>with open('filename','w') as f:\n    f.write(someString);<\/pre>\n<p>\uc774\uc0c1\uacfc \uac19\uc774 \ud30c\uc77c \ub514\uc2a4\ud06c\ub9bd\ud130\uc5d0 \ub300\ud574 \ubcc4\ub3c4\uc758 close()\uac00 \uc5c6\ub354\ub77c\ub3c4 \ucf54\ub4dc \ube14\ub7ed\uc744 \ube60\uc838\ub098\uc62c \ub54c \ucee8\ud14d\uc2a4\ud2b8 \ub9e4\ub2c8\uc800\uc5d0 \uc758\ud574 \uc790\ub3d9\uc73c\ub85c close()\uac00 \uc218\ud589\ub41c\ub2e4.<\/p>\n<hr \/>\n<h2><span style=\"font-size: 1.17em;\">\ud30c\uc77c \ucc98\ub9ac\uc5d0 \uad00\ud574\uc11c<\/span><\/h2>\n<p>\ud30c\uc77c\uc744 \ucc98\ub9ac\ud558\uace0\uc790 \ud560 \uacbd\uc6b0\uc5d0 \ud56d\uc0c1 \ud558\ub294 \uc77c\uc758 \uc21c\uc11c\ub294 \ub2e4\uc74c\uc758 \uacfc\uc815\uc744 \ub530\ub974\uac8c \ub41c\ub2e4.<\/p>\n<p>1. \ud30c\uc77c\uc744 \uc5f4\uace0<\/p>\n<p>2. \uc5f4\uc740 \ud30c\uc77c\uc744 \ucc98\ub9ac\ud558\uace0<\/p>\n<p>3. \uc5f4\uc5b4 \ub193\uc740 \ud30c\uc77c\uc744 \ub2eb\ub294\ub2e4.<\/p>\n<p>1. data_file = open(&#8216;test.dat&#8217;)<\/p>\n<p>2. print(data_file.readline(), end=&#8221;)<\/p>\n<p>3. data_file.close()<\/p>\n<p>\uadf8\ub7f0\ub370 \ud30c\uc77c\uc744 \uc5f4\uc5c8\uc73c\uba74 \ub2eb\uc544\uc918\uc57c \ud558\ub294 \uc791\uc5c5\uc740 \ud56d\uc0c1 \ud574\uc57c\ud55c\ub2e4. \ud654\uc7a5\uc2e4 \uac14\ub2e4 \uc624\uba74\uc11c \uc9c0\ud37c\ub97c \uc548\uc62c\ub9ac\uba74 \uc548\ub418\uc9c0 \uc54a\uaca0\ub294\uac00? ^^ \ub9e4\ubc88 \ub2eb\uc544\uc918\uc57c \ud558\ub294 \ubc18\ubcf5 \uc791\uc5c5\uc758 \uacbd\uc6b0 \ud30c\uc774\uc36c \uc778\ud130\ud504\ub9ac\ud130\uac00 \uc790\ub3d9\uc73c\ub85c \ub2eb\uc544\uc8fc\uba74 \uc88b\uc744 \uac83\uc774\ub2e4. \ube7c\uba39\uc744 \uc5fc\ub824\ub3c4 \uc5c6\uace0 \ub9d0\uc774\ub2e4. \uc774\ub807\uac8c\u00a0with as\ub97c \uc4f0\uba74 \uc778\ud130\ud504\ub9ac\ud130\uac00 \uc790\ub3d9\uc73c\ub85c \uad6c\ubb38\uc774 \ub05d\ub098\uba74 \ub9c8\ubb34\ub9ac(?)\ub97c \ud574\uc900\ub2e4. \uc0ac\uc6a9\ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<div>&#8220;with&#8221; expression [&#8220;as&#8221; target]\u00a0&#8220;:&#8221; suite<\/div>\n<div><\/div>\n<div>\uc704\uc758 \ucf54\ub4dc\ub97c with &#8230; as\ub85c \ubc14\uafb8\uba74 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/div>\n<div>with open(&#8216;test.dat&#8217;) as data_file:<\/div>\n<div>print(data_file.readline(), end=&#8221;)<\/div>\n<div><\/div>\n<div>\ucf54\ub4dc\uac00 \uc2ec\ud50c\ud574\uc9c4\ub2e4. \uc88b\uad70~ \uc5ec\uae30 \ub2e4\ub978 \uc608\uc81c\ub3c4 \uc788\ub2e4.<\/div>\n<div>with open(&#8216;output.txt&#8217;, &#8216;w&#8217;) as f:<\/div>\n<div>f.write(&#8216;Hi there!&#8217;)<\/div>\n<\/div>\n<div>\ucd9c\ucc98 : \u00a0<a href=\"http:\/\/ingorae.tistory.com\/505\">http:\/\/ingorae.tistory.com\/505<\/a>\u00a0,\u00a0<a href=\"http:\/\/mwultong.blogspot.com\/2006\/12\/python-list-array-size-length.html\">http:\/\/mwultong.blogspot.com\/2006\/12\/python-list-array-size-length.html<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>with \uad6c\ubb38\uc740 \ud30c\uc774\uc120 2.5\uc5d0\uc11c \ub3c4\uc785\ub41c \uae30\ub2a5\uc73c\ub85c \uc5b4\ub5a4 \ube14\ub7ed\uc5d0 \uc9c4\uc785\ud558\uace0 \ub098\uc62c \ub54c \uc9c0\uc815\ub41c \uac1d\uccb4(context manager)\ub85c \ud558\uc5ec\uae08 \uadf8 \uc2dc\uc791\uacfc \ub05d\uc5d0\uc11c \uc5b4\ub5a4 \ucc98\ub9ac\ub97c \ud558\ub3c4\ub85d \ud560 \ub54c \uc0ac\uc6a9\ud55c\ub2e4. with A: pass \uc704 \ucf54\ub4dc\uc5d0\uc11c A\ub294&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/1403"}],"collection":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1403"}],"version-history":[{"count":0,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/1403\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}