{"id":1789,"date":"2026-11-05T13:07:34","date_gmt":"2026-11-05T04:07:34","guid":{"rendered":"https:\/\/danlabs.kr\/?p=1789"},"modified":"2026-11-14T02:04:49","modified_gmt":"2026-11-13T17:04:49","slug":"python-tempfile-cleanup-named-files","status":"publish","type":"post","link":"https:\/\/danlabs.kr\/?p=1789","title":{"rendered":"Python tempfile \uc784\uc2dc \ud30c\uc77c \ub9cc\ub4e4\uae30 \u2014 \ud30c\uc77c \uc774\ub984 \ubcf4\uc7a5\uacfc \uc790\ub3d9 \uc815\ub9ac\uc758 \ucc28\uc774"},"content":{"rendered":"<p>Python\uc758 <code>tempfile<\/code> \ubaa8\ub4c8\uc740 \uc784\uc2dc \ud30c\uc77c\uacfc \uc784\uc2dc \ub514\ub809\ud130\ub9ac\ub97c \ub9cc\ub4dc\ub294 \uae30\ub2a5\uc744 \uc81c\uacf5\ud574\uc694.[1] \ud30c\uc77c \uac1d\uccb4\ub9cc \uc4f8\uc9c0, \ub2e4\ub978 \ud504\ub85c\uadf8\ub7a8\uc5d0 \uacbd\ub85c\ub97c \uc804\ub2ec\ud560\uc9c0, \uc5ec\ub7ec \ud30c\uc77c\uc744 \ud55c\uacf3\uc5d0 \ubaa8\uc744\uc9c0\uc5d0 \ub530\ub77c \uc0ac\uc6a9\ud560 \uc778\ud130\ud398\uc774\uc2a4\uac00 \ub2ec\ub77c\uc838\uc694. Python \uacf5\uc2dd \ubb38\uc11c\ub97c \ubc14\ud0d5\uc73c\ub85c \uac01 \uc778\ud130\ud398\uc774\uc2a4\uc758 \uc774\ub984 \ubcf4\uc7a5\uacfc \uc815\ub9ac \uc2dc\uc810\uc744 \uc0b4\ud3b4\ubd05\ub2c8\ub2e4.<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261105-inline1.jpg\" alt=\"\ud30c\uc77c \uac1d\uccb4\uc640 \ubcf4\uc774\ub294 \ud30c\uc77c \uc774\ub984\uc758 \uc120\ud0dd \ub3c4\uc2dd\"><\/figure>\n<h2>\ud30c\uc77c \uac1d\uccb4\ub9cc \ud544\uc694\ud560 \ub54c: TemporaryFile<\/h2>\n<p><code>TemporaryFile<\/code>\uc740 \uc784\uc2dc \uc800\uc7a5 \uacf5\uac04\uc73c\ub85c \uc4f8 \ud30c\uc77c \uac1d\uccb4\ub97c \ubc18\ud658\ud574\uc694. \uae30\ubcf8 \ubaa8\ub4dc\ub294 <code>w+b<\/code>\ub85c, \ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130\ub97c \uc4f0\uace0 \ud30c\uc77c\uc744 \ub2eb\uc9c0 \uc54a\uc740 \uc0c1\ud0dc\uc5d0\uc11c \ub2e4\uc2dc \uc77d\uc744 \uc218 \uc788\uc5b4\uc694.[1] \uc4f4 \ub0b4\uc6a9\uc744 \ucc98\uc74c\ubd80\ud130 \uc77d\uc73c\ub824\uba74 \ucf54\ub4dc\uc5d0\uc11c \ud30c\uc77c \uc704\uce58\ub97c \uc62e\uaca8\uc57c \ud574\uc694.<\/p>\n<pre><code class=\"language-python\">from tempfile import TemporaryFile\n\nwith TemporaryFile() as f:\n    f.write(b'hello')\n    f.seek(0)\n    print(f.read())\n<\/code><\/pre>\n<p>\uc774 \ud30c\uc77c\uc740 \ub2eb\ud788\uba74 \uc81c\uac70\ub3fc\uc694.[1] <code>with<\/code> \ube14\ub85d\uc744 \uc0ac\uc6a9\ud558\uba74 \ube14\ub85d\uc744 \ubc97\uc5b4\ub0a0 \ub54c \uc815\ub9ac\ub418\ubbc0\ub85c \ubcc4\ub3c4\uc758 \uc815\ub9ac \ucf54\ub4dc\ub97c \uc904\uc77c \uc218 \uc788\uc5b4\uc694.<\/p>\n<p>\ub2e4\ub9cc \ud30c\uc77c\uc774 \ubc18\ub4dc\uc2dc \ub208\uc5d0 \ubcf4\uc774\ub294 \uacbd\ub85c\ub97c \uac16\ub294\ub2e4\uace0 \uac00\uc815\ud574\uc11c\ub294 \uc548 \ub3fc\uc694. Unix\uc5d0\uc11c\ub294 \ub514\ub809\ud130\ub9ac \ud56d\ubaa9\uc774 \uc544\uc608 \ub9cc\ub4e4\uc5b4\uc9c0\uc9c0 \uc54a\uac70\ub098 \uc0dd\uc131 \uc9c1\ud6c4 \uc81c\uac70\ub420 \uc218 \uc788\uc73c\uba70, \ub2e4\ub978 \ud50c\ub7ab\ud3fc\uc740 \uac19\uc740 \ub3d9\uc791\uc744 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\uc544\uc694.[1]<\/p>\n<h2>\ubcf4\uc774\ub294 \ud30c\uc77c \uc774\ub984\uc774 \ud544\uc694\ud560 \ub54c: NamedTemporaryFile<\/h2>\n<p>\ub2e4\ub978 \ud504\ub85c\uadf8\ub7a8\uc5d0 \uc804\ub2ec\ud560 \ud30c\uc77c \uc774\ub984\uc774 \ud544\uc694\ud558\ub2e4\uba74 <code>NamedTemporaryFile<\/code>\uc744 \uac80\ud1a0\ud560 \uc218 \uc788\uc5b4\uc694. \uacf5\uc2dd \ubb38\uc11c\uc5d0 \ub530\ub974\uba74 \uc774 \ud568\uc218\ub294 \ud30c\uc77c \uc2dc\uc2a4\ud15c\uc5d0\uc11c \ubcf4\uc774\ub294 \uc774\ub984\uc744 \ubcf4\uc7a5\ud574\uc694. \ubc18\ud658 \uac1d\uccb4\uc758 <code>name<\/code> \uc18d\uc131\uc73c\ub85c \uc774\ub984\uc744 \ud655\uc778\ud560 \uc218 \uc788\uace0, <code>with<\/code> \uad6c\ubb38\uc5d0\uc11c\ub3c4 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc5b4\uc694.[1]<\/p>\n<pre><code class=\"language-python\">from tempfile import NamedTemporaryFile\n\nwith NamedTemporaryFile() as f:\n    print(f.name)\n<\/code><\/pre>\n<p>\uc774\ub984\uc774 \ubcf4\uc7a5\ub418\ub354\ub77c\ub3c4 \uc678\ubd80 \ud504\ub85c\uadf8\ub7a8\uc774 \uc5b8\uc81c\ub4e0 \ud30c\uc77c\uc744 \ub2e4\uc2dc \uc5f4 \uc218 \uc788\ub294 \uac83\uc740 \uc544\ub2c8\uc5d0\uc694. \uc6b4\uc601\uccb4\uc81c\ubcc4 \ud30c\uc77c \uacf5\uc720\uc640 \uc0ad\uc81c \uc870\uac74\uc744 \ud655\uc778\ud574\uc57c \ud574\uc694. \ud2b9\ud788 \ud30c\uc77c\uc744 \ub2eb\uc740 \ub4a4\uc5d0\ub3c4 \uacbd\ub85c\uac00 \ud544\uc694\ud55c \uc791\uc5c5\uc774\ub77c\uba74 \uae30\ubcf8 \uc815\ub9ac \uc2dc\uc810\uacfc \uc678\ubd80 \ud504\ub85c\uadf8\ub7a8\uc758 \uc2e4\ud589 \uc21c\uc11c\ub97c \ud568\uaed8 \uac80\ud1a0\ud574\uc57c \ud574\uc694. \uae30\ubcf8\uac12\uc744 \ubc14\uafd4 \ud30c\uc77c\uc744 \ub0a8\uae34\ub2e4\uba74 \uc774\ud6c4\uc758 \uc815\ub9ac \ucc45\uc784\ub3c4 \ucf54\ub4dc\uc5d0 \uba85\uc2dc\ud574\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261105-inline2.jpg\" alt=\"\uc784\uc2dc \ub514\ub809\ud130\ub9ac \uc0ac\uc6a9 \ud750\ub984 \ub3c4\uc2dd\"><\/figure>\n<h2>\uc5ec\ub7ec \ud30c\uc77c\uc744 \ubaa8\uc744 \ub54c: TemporaryDirectory<\/h2>\n<p>\uc5ec\ub7ec \uc911\uac04 \uacb0\uacfc\ubb3c\uc744 \ud55c\uacf3\uc5d0 \ubaa8\uc544\uc57c \ud55c\ub2e4\uba74 <code>TemporaryDirectory<\/code>\ub97c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc5b4\uc694. Python \ubb38\uc11c\ub294 \uc774\ub97c \uc790\ub3d9 \uc815\ub9ac\ub97c \uc81c\uacf5\ud558\uace0 \ucee8\ud14d\uc2a4\ud2b8 \uad00\ub9ac\uc790\ub85c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub294 \uace0\uc218\uc900 \uc778\ud130\ud398\uc774\uc2a4\ub85c \ubd84\ub958\ud574\uc694.[1]<\/p>\n<pre><code class=\"language-python\">from tempfile import TemporaryDirectory\nfrom pathlib import Path\n\nwith TemporaryDirectory() as directory:\n    output = Path(directory) \/ 'result.txt'\n    output.write_text('hello', encoding='utf-8')\n    print(output.read_text(encoding='utf-8'))\n<\/code><\/pre>\n<p>\uc704 \uc608\uc81c\uc758 \uacbd\ub85c\ub294 \ube14\ub85d \uc548\uc5d0\uc11c \uc0ac\uc6a9\ud574\uc694. \ud504\ub85c\uadf8\ub7a8\uc758 \ub2e4\ub978 \ubd80\ubd84\uc5d0\uc11c \ub098\uc911\uc5d0 \ud30c\uc77c\uc744 \uc77d\uc5b4\uc57c \ud55c\ub2e4\uba74, \ud544\uc694\ud55c \ub370\uc774\ud130\ub97c \uc784\uc2dc \ub514\ub809\ud130\ub9ac\uc758 \uc218\uba85\uc774 \ub05d\ub098\uae30 \uc804\uc5d0 \ubcc4\ub3c4\ub85c \uc800\uc7a5\ud558\ub3c4\ub85d \uc124\uacc4\ud574\uc57c \ud574\uc694. \uc784\uc2dc \uacb0\uacfc\ubb3c\uacfc \ubcf4\uc874\ud560 \uacb0\uacfc\ubb3c\uc744 \uad6c\ubd84\ud558\ub294 \uac83\uc774 \uc815\ub9ac \uc2dc\uc810\uc744 \uc815\ud558\ub294 \uae30\uc900\uc774 \ub429\ub2c8\ub2e4.<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261105-inline3.jpg\" alt=\"\uc790\ub3d9 \uc815\ub9ac\uc640 \uc218\ub3d9 \uc815\ub9ac\ub97c \ube44\uad50\ud558\ub294 \ub3c4\uc2dd\"><\/figure>\n<h2>\uc218\ub3d9 \uc815\ub9ac\uac00 \ud544\uc694\ud55c \ud568\uc218\uc640 \ubc30\ud3ec \ud658\uacbd \ud655\uc778<\/h2>\n<p><code>mkstemp()<\/code>\uc640 <code>mkdtemp()<\/code>\ub294 \uc218\ub3d9 \uc815\ub9ac\uac00 \ud544\uc694\ud55c \uc800\uc218\uc900 \ud568\uc218\uc608\uc694.[1] \uc138\ubd80 \uc81c\uc5b4\uac00 \ud544\uc694\ud560 \ub54c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc9c0\ub9cc, \uc624\ub958\uac00 \ubc1c\uc0dd\ud558\ub294 \uc2e4\ud589 \uacbd\ub85c\uc5d0\uc11c\ub3c4 \uc815\ub9ac\uac00 \uc774\ub904\uc9c0\ub3c4\ub85d \uc9c1\uc811 \ucc98\ub9ac\ud574\uc57c \ud574\uc694. \uc790\ub3d9 \uc815\ub9ac\uac00 \ubaa9\uc801\uc774\ub77c\uba74 \uace0\uc218\uc900 \uc778\ud130\ud398\uc774\uc2a4\ubd80\ud130 \uac80\ud1a0\ud558\ub294 \ud3b8\uc774 \ub2e8\uc21c\ud574\uc694.<\/p>\n<p>\uc801\uc6a9 \uc804\uc5d0\ub294 \uc138 \uac00\uc9c0 \uc694\uad6c\ub97c \uad6c\ubd84\ud558\uc138\uc694. \ud30c\uc77c \uac1d\uccb4\ub9cc \ud544\uc694\ud55c\uc9c0, \ub2e4\ub978 \ud504\ub85c\uadf8\ub7a8\uc5d0 \ubcf4\uc774\ub294 \uc774\ub984\uc774 \ud544\uc694\ud55c\uc9c0, \uc5ec\ub7ec \ud30c\uc77c\uc744 \ubcf4\uad00\ud560 \ub514\ub809\ud130\ub9ac\uac00 \ud544\uc694\ud55c\uc9c0\uc608\uc694. \uc120\ud0dd\ud55c \ub4a4\uc5d0\ub294 \uc2e4\uc81c \ubc30\ud3ec \uc6b4\uc601\uccb4\uc81c\uc5d0\uc11c \ud30c\uc77c \uc5f4\uae30\uc640 \uc815\ub9ac \uc2dc\uc810\uc744 \uc2dc\ud5d8\ud574\uc57c \ud574\uc694. \uc678\ubd80 \ud504\ub85c\uadf8\ub7a8\uc744 \ud638\ucd9c\ud558\ub294 \uc791\uc5c5\uc774\ub77c\uba74 <a href=\"https:\/\/danlabs.kr\/?p=1682\">subprocess.run\uc758 \uc624\ub958 \ucc98\ub9ac<\/a>\ub3c4 \ud568\uaed8 \ucc38\uace0\ud560 \uc218 \uc788\uc5b4\uc694.<\/p>\n<h2>\ucd9c\ucc98<\/h2>\n<p>[1] Python \uacf5\uc2dd tempfile \ubb38\uc11c \u2014 https:\/\/docs.python.org\/3\/library\/tempfile.html. \uac01 \uc778\ud130\ud398\uc774\uc2a4\uc758 \uae30\ubcf8 \ub3d9\uc791, \uc774\ub984 \ubcf4\uc7a5, \uc790\ub3d9\u00b7\uc218\ub3d9 \uc815\ub9ac \uc870\uac74\uc740 \uc774 \ubb38\uc11c\ub97c \uae30\uc900\uc73c\ub85c \uc124\uba85\ud588\uc5b4\uc694.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud30c\uc77c \uac1d\uccb4\ub9cc \ud544\uc694\ud560 \ub54c\uc640 \uc678\ubd80 \ud504\ub85c\uadf8\ub7a8\uc5d0 \uacbd\ub85c\ub97c \uc804\ub2ec\ud560 \ub54c\ub294 \uc0ac\uc6a9\ud560 tempfile \uc778\ud130\ud398\uc774\uc2a4\uac00 \ub2ec\ub77c\uc838\uc694. \ud30c\uc77c \uc774\ub984\uc758 \ubcf4\uc7a5 \uc5ec\ubd80\uc640 \uc790\ub3d9 \uc815\ub9ac \uc2dc\uc810\uc744 \uad6c\ubd84\ud558\uace0, \uc774\ub984\uc774 \uc788\uc5b4\ub3c4 \uc6b4\uc601\uccb4\uc81c\uc5d0 \ub530\ub77c \ub2e4\uc2dc \uc5f4\uae30 \uc870\uac74\uc774 \ub2ec\ub77c\uc9c0\ub294 \uc810\uc744 \uc9da\uc5b4\uc694.<\/p>\n","protected":false},"author":1,"featured_media":2670,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"featured_image_urls":{"full":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept.webp",1536,1024,false],"thumbnail":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-150x150.webp",150,150,true],"medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-300x200.webp",300,200,true],"medium_large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-768x512.webp",640,427,true],"large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-1024x683.webp",640,427,true],"1536x1536":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept.webp",1536,1024,false],"2048x2048":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept.webp",1536,1024,false],"morenews-large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept.webp",825,550,false],"morenews-medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept.webp",590,393,false],"danlabs-list-small":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-366x190.webp",366,190,true],"danlabs-list-retina":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/python-tempfile-cleanup-files-1789-concept-1464x760.webp",1464,760,true]},"author_info":{"display_name":"DanLABs","author_link":"https:\/\/danlabs.kr\/author\/hello-danlabs-kr"},"category_info":"<a href=\"https:\/\/danlabs.kr\/?cat=19\" rel=\"category\">\uac1c\ubc1c<\/a>","tag_info":"\uac1c\ubc1c","comment_count":"1","_links":{"self":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/1789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1789"}],"version-history":[{"count":3,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/1789\/revisions"}],"predecessor-version":[{"id":2677,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/1789\/revisions\/2677"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/media\/2670"}],"wp:attachment":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}