{"id":499,"date":"2018-09-19T12:32:41","date_gmt":"2018-09-19T03:32:41","guid":{"rendered":"http:\/\/dong1lkim.oboki.net\/?p=499"},"modified":"2019-09-01T22:21:04","modified_gmt":"2019-09-01T13:21:04","slug":"python-%ed%8c%8c%ec%9d%bc-%ec%9e%85%ec%b6%9c%eb%a0%a5","status":"publish","type":"post","link":"https:\/\/oboki.net\/workspace\/python\/python-%ed%8c%8c%ec%9d%bc-%ec%9e%85%ec%b6%9c%eb%a0%a5\/","title":{"rendered":"[Python] \ud30c\uc77c \uc785\ucd9c\ub825"},"content":{"rendered":"<h1>Python \ud30c\uc77c \uc785\ucd9c\ub825<\/h1>\n<p>\uae30\ubcf8 \ud568\uc218\uc778 open() \uc744 \uc774\uc6a9\ud558\uc5ec \ud30c\uc77c \uc785\ucd9c\ub825\uc774 \uac00\ub2a5\ud558\ub2e4.<\/p>\n<p><code>help(open)<\/code><\/p>\n<pre><code class=\"py\">open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)\n    Open file and return a stream.  Raise IOError upon failure.\n<\/code><\/pre>\n<ul>\n<li><code>file<\/code><br \/>\n\uc720\uc77c\ud558\uac8c \ud544\uc218 \uc785\ub825\uc0ac\ud56d\uc774\uba70 \ud30c\uc77c \uacbd\ub85c\ub97c \uc9c0\uc815\ud574\uc900\ub2e4.<\/li>\n<li><code>mode<\/code><br \/>\n\uc77d\uae30\/\uc4f0\uae30\uc5d0 \ub300\ud55c \uc0c1\uc138 \ubaa8\ub4dc\ub97c \uc124\uc815\ud55c\ub2e4. \uae30\ubcf8\uac12\uc740 &#8216;rt&#8217; \uc774\uba70 \ud14d\uc2a4\ud2b8\ud30c\uc77c\uc744 \uc77d\ub294 \ubaa8\ub4dc\uc774\ub2e4.<br \/>\n\uc5b4\ub5a0\ud55c \uc791\uc5c5\uc744 \uc218\ud589\ud558\ub294\uc9c0\uc5d0 \ub530\ub77c <strong>&#8216;r&#8217;,&#8217;w&#8217;,&#8217;a&#8217;<\/strong> \ubb38\uc790\uc640 \ud30c\uc77c \ud615\ud0dc\uac00 \uc5b4\ub5a4\uc9c0\uc5d0 \ub530\ub77c <strong>&#8216;t&#8217;,&#8217;b&#8217;<\/strong> \ubb38\uc790\ub97c \uc870\ud569\ud558\uc5ec \uc785\ub825\ud55c\ub2e4.<\/li>\n<li><code>encoding<\/code><br \/>\n\ub300\uc0c1 \ud30c\uc77c\uc758 \uc778\ucf54\ub529\uc744 \uc9c0\uc815\ud55c\ub2e4. \uae30\ubcf8\uac12\uc740 &#8216;utf-8&#8217;<\/li>\n<\/ul>\n<h2>\ud14d\uc2a4\ud2b8 \ud30c\uc77c \uc4f0\uae30<\/h2>\n<p><code>write<\/code> \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9\ud574\uc11c \ud14d\uc2a4\ud2b8\ub97c \ud30c\uc77c\uc5d0 \uae30\ub85d\ud560 \uc218 \uc788\ub2e4. newline \uc740 \uba85\uc2dc\ub97c \ud574\uc8fc\uc5b4\uc57c \ud55c\ub2e4.<\/p>\n<pre><code class=\"py\">file = open('say_i_love_you-tyrone_wells.txt',mode='wt',encoding='utf-8')\n\nfile.write('Old man on a red park bench\\n')\nfile.write('Sitting here next to me\\n')\nfile.write('Started talking bout the love he lost\\n')\nfile.write('He said boy don\\'t end up like me\\n')\nfile.write('I\\'m sitting here by myself\\n')\nfile.write('Because of what I never said\\n')\nfile.write('Pay attention son listen close\\n')\nfile.write('You gotta get this though your head\\n')\nfile.write('\\n')\nfile.write('Oooh, don\\'t let her slip away\\n')\nfile.write('Oooh, say I love you every day\\n')\nfile.write('\\n')\nfile.write('I finally found her and it feels so good\\n')\nfile.write('I gotta lotta love in this heart\\n')\nfile.write('She\\'s a beauty and she\\'s teaching me\\n')\nfile.write('To stop and look up at the stars\\n')\nfile.write('I gotta show her what she means to me\\n')\nfile.write('So she\\'ll know\\n')\nfile.write('That I love her more than anything\\n')\nfile.write('And I\\'m never gonna let her go\\n')\nfile.write('\\n')\nfile.write('Oooo, I won\\'t let her slip away\\n')\nfile.write('Oooo, I\\'ll say I love you every day\\n')\n\nfile.close()\n<\/code><\/pre>\n<h2>\ud14d\uc2a4\ud2b8 \ud30c\uc77c \uc77d\uae30<\/h2>\n<p>REPL(READ EVAL PRINT LOOP) \ud658\uacbd\uc5d0\uc11c\ub294 \ud14d\uc2a4\ud2b8 \ud30c\uc77c\uc744 \uc5b4\ub5bb\uac8c \uc77d\uc5b4\ub4e4\uc774\ub294\uc9c0 \ubc14\ub85c\ubc14\ub85c \ud655\uc778\ud560 \uc218 \uc788\ub2e4.<\/p>\n<p><code>read(length)<\/code> \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9\ud558\uba74 \ud604\uc7ac \uc778\ub371\uc2a4\ubd80\ud130 <code>length<\/code> \uac12\ub9cc\ud07c\uc758 \ubb38\uc790\uc5f4\uc744 \ubc18\ud658\ud574\uc900\ub2e4. \uc778\ub371\uc2a4\ub294 \ud574\ub2f9 \uac12\ub9cc\ud07c \ub4a4\ub85c \uc774\ub3d9\ub41c\ub2e4.<\/p>\n<p><code>read()<\/code> \uba54\uc18c\ub4dc\ub97c \uc778\uc790 \uc5c6\uc774 \uc0ac\uc6a9\ud558\uba74 \ud604\uc7ac \uc704\uce58\uc5d0\uc11c\ubd80\ud130 \ud14d\uc2a4\ud2b8 \ud30c\uc77c\uc758 \ub9c8\uc9c0\ub9c9\uae4c\uc9c0 \ubaa8\ub4e0 \ubb38\uc790\uc5f4\uc744 \ubc18\ud658\ud574\uc900\ub2e4.<\/p>\n<p><code>seek(index)<\/code> \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9\ud558\uba74 read \ub4f1\uc73c\ub85c \uc778\ud574 \ubcc0\uacbd\ub41c \ud604\uc7ac index \uc704\uce58\ub97c \ucd08\uae30\ud654 \ud558\uac70\ub098 \uc6d0\ud558\ub294 \uc704\uce58\ub85c \uc62e\uae38 \uc218 \uc788\ub2e4.<\/p>\n<p><code>readlines()<\/code> \uba54\uc18c\ub4dc\ub97c \uc0ac\uc6a9\ud558\uba74 newline\uc73c\ub85c \uad6c\ubd84\uc9c0\uc5b4 \uac01 \ud589\uc744 \uc6d0\uc18c\ub85c \ud558\ub294 \ub9ac\uc2a4\ud2b8\ub97c \ubc18\ud658\ud55c\ub2e4.<\/p>\n<pre><code class=\"py\">file = open('say_i_love_you-tyrone_wells.txt',mode='rt',encoding='utf-8')\n\n>&gt;&gt; file = open('say_i_love_you-tyrone_wells.txt',mode='rt',encoding='utf-8')\n>&gt;&gt; \n>&gt;&gt; file.read(10)\n'Old man on'\n>&gt;&gt; file.read(10)\n' a red par'\n>&gt;&gt; file.read(10)\n'k bench\\nSi'\n>&gt;&gt; file.read(10)\n'tting here'\n>&gt;&gt; file.read(10)\n' next to m'\n>&gt;&gt; file.seek(0)\n0\n>&gt;&gt; file.read(10)\n'Old man on'\n>&gt;&gt; file.read(10)\n' a red par'\n>&gt;&gt; file.read(10)\n'k bench\\nSi'\n>&gt;&gt; file.read()\n\"tting here next to me\\nStarted talking bout the love he lost\\nHe said boy don't end up like me\\nI'm sitting here by myself\\nBecause of what I never said\\nPay attention son listen close\\nYou gotta get this though your head\\n\\nOooh, don't let her slip away\\nOooh, say I love you every day\\n\\nI finally found her and it feels so good\\nI gotta lotta love in this heart\\nShe's a beauty and she's teaching me\\nTo stop and look up at the stars\\nI gotta show her what she means to me\\nSo she'll know\\nThat I love her more than anything\\nAnd I'm never gonna let her go\\n\\nOooo, I won't let her slip away\\nOooo, I'll say I love you every day\\n\"\n>&gt;&gt; file.seek(0)\n0\n>&gt;&gt; file.readline()\n'Old man on a red park bench\\n'\n>&gt;&gt; file.readline()\n'Sitting here next to me\\n'\n>&gt;&gt; file.readline()\n'Started talking bout the love he lost\\n'\n>&gt;&gt; file.readline()\n\"He said boy don't end up like me\\n\"\n>&gt;&gt; file.seek(0)\n0\n>&gt;&gt; file.readlines()\n['Old man on a red park bench\\n', 'Sitting here next to me\\n', 'Started talking bout the love he lost\\n', \"He said boy don't end up like me\\n\", \"I'm sitting here by myself\\n\", 'Because of what I never said\\n', 'Pay attention son listen close\\n', 'You gotta get this though your head\\n', '\\n', \"Oooh, don't let her slip away\\n\", 'Oooh, say I love you every day\\n', '\\n', 'I finally found her and it feels so good\\n', 'I gotta lotta love in this heart\\n', \"She's a beauty and she's teaching me\\n\", 'To stop and look up at the stars\\n', 'I gotta show her what she means to me\\n', \"So she'll know\\n\", 'That I love her more than anything\\n', \"And I'm never gonna let her go\\n\", '\\n', \"Oooo, I won't let her slip away\\n\", \"Oooo, I'll say I love you every day\\n\"]\n>&gt;&gt; file.close()\n<\/code><\/pre>\n<h2>\ud14d\uc2a4\ud2b8 \ud30c\uc77c\uc5d0 \ucd94\uac00\ud558\uae30<\/h2>\n<p><code>writelines(list_of_string)<\/code> \uba54\uc18c\ub4dc\ub97c \uc774\uc6a9\ud574 \ubb38\uc790\uc5f4 \ub9ac\uc2a4\ud2b8\uc758 \uc6d0\uc18c\ub4e4\uc744 \ud574\ub2f9 \ud30c\uc77c\uc758 \ub9c8\uc9c0\ub9c9\uc5d0 \ucd94\uac00\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"py\">file = open('say_i_love_you-tyrone_wells.txt',mode='at',encoding='utf-8')\nfile.writelines(['\\n\\n','say I Love You\\n','song by Tyrone Wells'])\nfile.close()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python \ud30c\uc77c \uc785\ucd9c\ub825 \uae30\ubcf8 \ud568\uc218\uc778 open() \uc744 \uc774\uc6a9\ud558\uc5ec \ud30c\uc77c \uc785\ucd9c\ub825\uc774 \uac00\ub2a5\ud558\ub2e4. help(open) open(file, mode=&#8217;r&#8217;, buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) Open file and return a stream. Raise IOError upon failure. file \uc720\uc77c\ud558\uac8c \ud544\uc218 \uc785\ub825\uc0ac\ud56d\uc774\uba70 \ud30c\uc77c \uacbd\ub85c\ub97c \uc9c0\uc815\ud574\uc900\ub2e4. mode \uc77d\uae30\/\uc4f0\uae30\uc5d0 \ub300\ud55c \uc0c1\uc138 \ubaa8\ub4dc\ub97c \uc124\uc815\ud55c\ub2e4. \uae30\ubcf8\uac12\uc740 &#8216;rt&#8217; \uc774\uba70 \ud14d\uc2a4\ud2b8\ud30c\uc77c\uc744 \uc77d\ub294 \ubaa8\ub4dc\uc774\ub2e4. \uc5b4\ub5a0\ud55c \uc791\uc5c5\uc744 \uc218\ud589\ud558\ub294\uc9c0\uc5d0 \ub530\ub77c &#8216;r&#8217;,&#8217;w&#8217;,&#8217;a&#8217; \ubb38\uc790\uc640 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[34],"class_list":["post-499","post","type-post","status-publish","format-standard","hentry","category-python","tag-python"],"_links":{"self":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/comments?post=499"}],"version-history":[{"count":5,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/499\/revisions\/1231"}],"wp:attachment":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/media?parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/categories?post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/tags?post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}