{"id":2119,"date":"2020-01-18T22:34:27","date_gmt":"2020-01-18T13:34:27","guid":{"rendered":"http:\/\/141.164.34.82\/?p=2119"},"modified":"2020-01-18T22:45:16","modified_gmt":"2020-01-18T13:45:16","slug":"python-%eb%94%94%eb%b2%84%ea%b9%85-print-%ed%95%a8%ec%88%98-%ea%b0%80%eb%a1%9c%ec%b1%84%ea%b8%b0","status":"publish","type":"post","link":"http:\/\/ds.sumeun.org\/?p=2119","title":{"rendered":"Python \ub514\ubc84\uae45: `print` \ud568\uc218 \uac00\ub85c\ucc44\uae30"},"content":{"rendered":"<h2>\ub514\ubc84\uae45<\/h2>\n<blockquote><p>\ub514\ubc84\uae45\uc740 \ud504\ub85c\uadf8\ub798\uba38\uc758 \uc219\uba85\uc774\ub2e4.<\/p><\/blockquote>\n<p>\uc0ac\ub78c\ub4e4\uc740 \ud504\ub85c\uadf8\ub798\uba38\uac00 \ud558\ub294 \uc77c\uc758 80%\uac00 \ub514\ubc84\uae45\uc774\ub77c\uace0\ub3c4 \ud55c\ub2e4.<\/p>\n<h2>Python\uacfc \ub514\ubc84\uae45<\/h2>\n<p>\ud30c\uc774\uc36c\uc744 \uc4f0\uba74\uc11c \ubd88\ud3b8\ud55c \uc810\uc758 \ud558\ub098\ub294 <strong>\ub514\ubc84\uae45<\/strong>\uc774\ub2e4. \ud2b9\ud788 \uc2e4\ud589\ud558\ub294\ub370 \uc2dc\uac04\uc774 \ub9ce\uc774 \uac78\ub9ac\ub294 \ud504\ub85c\uadf8\ub7a8\uc758 \uacbd\uc6b0\ub294 \uc2e4\ud589 \uacfc\uc815\uc744 \uacc4\uc18d \uc549\uc544\uc11c \ubaa8\ub2c8\ud130\ub9c1\ud558\uae30 \ud798\ub4e4\uae30 \ub54c\ubb38\uc5d0 \uc5ec\ub7ec \uac00\uc9c0 \uc218\ub2e8\uc744 \ub9c8\ub828\ud574\uc57c \ud55c\ub2e4. \ud55c\uac00\uc9c0 \ubc29\ubc95\uc740 \ucd9c\ub825\uc744 \ud654\uc77c\ub85c \uc800\uc7a5\ud558\ub294 \uac83\uc774\ub2e4. \ud558\uc9c0\ub9cc \uc5b4\ub5bb\uac8c?<\/p>\n<h2>\uba87 \uac00\uc9c0 \uac00\ub2a5\uc131<\/h2>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/4675728\/redirect-stdout-to-a-file-in-python\">Redirect stout to a file in Python<\/a><\/li>\n<li>\uc720\ub2c9\uc2a4\ub97c \uc4f4\ub2e4\uba74, \uc720\ub2c9\uc2a4 \ucc28\uc6d0\uc5d0\uc11c \ubaa8\ub4e0 \ucd9c\ub825\uacfc \uc5d0\ub7ec \uba54\uc2dc\uc9c0\ub97c \ud654\uc77c\ub85c \ubcf4\ub0b8\ub2e4.<\/li>\n<\/ul>\n<pre>python3 -u foo.py 2&gt;&amp;1 | tee log.txt\r\n<\/pre>\n<ul>\n<li>Python <a href=\"https:\/\/docs.python.org\/ko\/3.7\/howto\/logging.html\">logging<\/a> module\ub97c \uc0ac\uc6a9\ud55c\ub2e4.<\/li>\n<\/ul>\n<p>\uc704\uc758 \ubc29\ubc95\ub4e4\uc744 \uc2dc\ub3c4\ud574 \ubcf8 \uacb0\uacfc, \ubaa8\ub450 \uadf8\ub2e4\uc9c0 \ub9cc\uc871\uc2a4\ub7fd\uc9c0 \ubabb\ud588\ub2e4.<\/p>\n<ul>\n<li>\ud45c\uc900\ucd9c\ub825 <code>stout<\/code>\uc744 \ud654\uc77c\ub85c \ubcf4\ub0b4\ub294 \uac83\uc740 \uc0dd\uac01\ubcf4\ub2e4 \uc798 \ub418\uc9c0 \uc54a\uc558\ub2e4.<\/li>\n<li><code>python3 -u foo.py 2&gt;&amp;1 | tee filename.txt<\/code>\uc758 \uacbd\uc6b0\ub294 \uac00\uc7a5 \uac04\ub2e8\ud558\uac8c \uc4f8 \uc218 \uc788\ub294 \ubc29\ubc95\uc774\uc9c0\ub9cc, \uc2e4\ud589 \uc2dc\uac04\uc774 \uae38\uc5b4\uc9c0\uba74 <code>filename.txt<\/code>\uac00 \uc6a9\ub7c9\uc774 \uc9c0\ub098\uce58\uac8c \ucee4\uc9c0\ub294 \ubb38\uc81c\uac00 \uc0dd\uae34\ub2e4.<\/li>\n<li><code>logging<\/code>\uc740 \uc88b\uc740 \ubc29\ubc95\uc774\uc9c0\ub9cc, \uae30\uc874\uc758 \uc18c\uc2a4\ub97c \uace0\uccd0\uc57c \ud55c\ub2e4\ub294 \ubb38\uc81c\uac00 \uc788\ub2e4. \uadf8\ub9ac\uace0 <code>logging<\/code>\uc744 \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc744 \ubc30\uc6cc\uc57c \ud55c\ub2e4!<\/li>\n<\/ul>\n<h2><code>newprint.py<\/code><\/h2>\n<p>\uadf8\ub798\uc11c \uae30\uc874\uc758 <code>print<\/code>\ub97c \uadf8\ub300\ub85c \uc4f8 \uc218 \uc788\ub294 \ubc29\ubc95\uc744 \uace0\uc548\ud558\uac8c \ub418\uc5c8\ub2e4. \ub2e4\uc74c\uc744 <code>newprint.py<\/code>\ub85c \uc800\uc7a5\ud55c \ud6c4, <code>print<\/code>\ub97c \uc0ac\uc6a9\ud558\uc5ec \ub514\ubc84\uae45\uc5d0 \ud544\uc694\ud55c \ub0b4\uc6a9\uc744 \ud654\uba74\uacfc \ud654\uc77c\uc5d0 \ub3d9\uc2dc\uc5d0 \ucd9c\ub825\ud558\uace0\uc790 \ud560 \ub54c, \ucf54\ub4dc\uc758 \uccab \uba38\ub9ac\uc5d0 <code>import newprint<\/code>, <code>from newprint import print<\/code>\ub9cc \uc0bd\uc785\ud558\uba74, <code>print<\/code> \ub0b4\uc6a9\uc774 <code>log_\ub144-\uc6d4-\uc77c.py<\/code>\ub85c \uc800\uc7a5\ub41c\ub2e4.<\/p>\n<pre><code class=\"python\"># save the following as newprint.py\r\nfrom datetime import datetime, date\r\n\r\nif not 'print0' in dir():\r\n    print0 = print\r\n\r\ndef print2(*argv, **kwarg):\r\n    if 'file' in kwarg:\r\n        file=kwarg['file']\r\n#        if file is not fDebug:\r\n#            print0('strange file is not fDebug!')\r\n#            print0(file)\r\n#            print0(fDebug)\r\n#            print0('strange file is not fDebug!', file=fDebug)\r\n#            print0(file, file=fDebug)\r\n#            print0(fDebug, file=fDebug)        \r\n    if 'end' in kwarg:        \r\n        print0(*argv, end = kwarg['end'])\r\n        print0(*argv, end = kwarg['end'], file=fDebug)\r\n    else:\r\n        print0(*argv, end='\\n')\r\n        print0(*argv, end='\\n', file=fDebug)\r\n\r\nprint = print2\r\n\r\ndebug = True\r\ntoday = date.today()\r\nfnDebug = 'log_'+today.strftime(\"%Y-%m-%d\")+'.txt'\r\nfDebug = open(fnDebug, 'a')\r\n<\/code><\/pre>\n<p>\uc608\ub97c \ub4e4\uc5b4 \ub2e4\uc74c\uacfc \uac19\uc774 \uc4f0\ub294 \uac83\uc774\ub2e4.<\/p>\n<pre><code class=\"python\">import newprint\r\nfrom newprint import print0, print2, print\r\n\r\nfrom datetime import datetime, date\r\ntoday = date.today()\r\nprint('Current time : ', today)\r\n<\/code><\/pre>\n<pre>## Current time :  2020-01-18\r\n<\/pre>\n<h3><code>log<\/code> \ud654\uc77c \ubcc0\uacbd<\/h3>\n<p>\ub9cc\uc57d \ud504\ub85c\uadf8\ub7a8\uc774 \ud558\ub8e8\ub97c \ub118\uc5b4 \uc2e4\ud589\ub418\uc5b4 <code>log-().txt<\/code>\uc758 \ub0a0\uc9dc\ub97c \ubc14\uafd4\uc57c \ud55c\ub2e4\uba74 \ub2e4\uc74c\uc758 \ub8e8\ud2f4\uc73c\ub85c \uac00\ub2a5\ud558\ub2e4.<\/p>\n<pre><code class=\"python\">today = date.today()\r\nif (today &gt; newprint.today):\r\n    newprint.fDebug.close() \r\n    newprint.today = today\r\n    newprint.fnDebug = 'log_'+today.strftime(\"%Y-%m-%d\")+'.txt'\r\n    newprint.fDebug = open(newprint.fnDebug, 'a')   \r\n<\/code><\/pre>\n<h2>\ub9c8\ubb34\ub9ac<\/h2>\n<ul>\n<li>\ud639\uc2dc \uc880 \ub354 \ub098\uc740 \ubc29\ubc95\uc774 \uc788\ub2e4\uba74 \ub313\uae00\ub85c \uc54c\ub824\uc8fc\uc138\uc694!<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\ub514\ubc84\uae45 \ub514\ubc84\uae45\uc740 \ud504\ub85c\uadf8\ub798\uba38\uc758 \uc219\uba85\uc774\ub2e4. \uc0ac\ub78c\ub4e4\uc740 \ud504\ub85c\uadf8\ub798\uba38\uac00 \ud558\ub294 \uc77c\uc758 80%\uac00 \ub514\ubc84\uae45\uc774\ub77c\uace0\ub3c4 \ud55c\ub2e4. Python\uacfc \ub514\ubc84\uae45 \ud30c\uc774\uc36c\uc744 \uc4f0\uba74\uc11c \ubd88\ud3b8\ud55c \uc810\uc758 \ud558\ub098\ub294 \ub514\ubc84\uae45\uc774\ub2e4. \ud2b9\ud788 \uc2e4\ud589\ud558\ub294\ub370 \uc2dc\uac04\uc774 \ub9ce\uc774 \uac78\ub9ac\ub294 \ud504\ub85c\uadf8\ub7a8\uc758 \uacbd\uc6b0\ub294 \uc2e4\ud589 \uacfc\uc815\uc744 \uacc4\uc18d \uc549\uc544\uc11c \ubaa8\ub2c8\ud130\ub9c1\ud558\uae30 \ud798\ub4e4\uae30 \ub54c\ubb38\uc5d0 \uc5ec\ub7ec \uac00\uc9c0 \uc218\ub2e8\uc744 \ub9c8\ub828\ud574\uc57c \ud55c\ub2e4. \ud55c\uac00\uc9c0 \ubc29\ubc95\uc740 \ucd9c\ub825\uc744 \ud654\uc77c\ub85c \uc800\uc7a5\ud558\ub294 \uac83\uc774\ub2e4. \ud558\uc9c0\ub9cc \uc5b4\ub5bb\uac8c? \uba87 \uac00\uc9c0 \uac00\ub2a5\uc131 Redirect stout to a file in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2122,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[264],"tags":[432,340,433,435,434,436],"jetpack_featured_media_url":"http:\/\/ds.sumeun.org\/wp-content\/uploads\/2020\/01\/newprint.png","_links":{"self":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/2119"}],"collection":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2119"}],"version-history":[{"count":2,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/2119\/revisions"}],"predecessor-version":[{"id":2121,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/2119\/revisions\/2121"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/media\/2122"}],"wp:attachment":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2119"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}