{"id":226,"date":"2026-05-14T21:54:07","date_gmt":"2026-05-14T13:54:07","guid":{"rendered":"https:\/\/junai.ai\/blog\/python-files-13\/"},"modified":"2026-05-17T07:31:21","modified_gmt":"2026-05-16T23:31:21","slug":"python-files-13","status":"publish","type":"post","link":"https:\/\/junai.ai\/blog\/python-files-13\/","title":{"rendered":"\ud30c\uc774\uc36c \ud30c\uc77c \uc77d\uae30\u00b7\uc4f0\uae30 \u2014 open\u00b7with\u00b7csv\u00b7json (13\ud3b8)"},"content":{"rendered":"\n<!-- WordPress REST API \ubc1c\ud589\uc6a9 HTML (\uc790\ub3d9 \uc0dd\uc131) -->\n<!-- WP-FEATURED-MEDIA-ID: 592 -->\n<div style=\"max-width:800px;margin:0 auto;\">\n<style>\n\/* js-textbook \u2014 PostgreSQL \uad50\uc7ac \ub3d9\uc77c \ud314\ub808\ud2b8 *\/\n:root {\n  --color-primary: #336791;\n  --color-accent: #60a5fa;\n  --color-bg: #fafafa;\n  --color-bg-card: #ffffff;\n  --color-text: #1e293b;\n  --color-text-muted: #64748b;\n  --hero-start: #0f172a;\n  --hero-end: #336791;\n  --font-body: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;\n  --size-body: 17px;\n  --line-height: 1.75;\n}\n* { box-sizing: border-box; }\n.container { max-width: 760px; margin: 0 auto; padding: 0 22px 80px; }\n.hero { background: linear-gradient(135deg, var(--hero-start) 0%, var(--hero-end) 100%); color: #fff; padding: 72px 22px 56px; text-align: center; }\n.hero .badge { display: inline-block; background: rgba(96,165,250,0.18); color: var(--color-accent); padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; letter-spacing: 0.5px; margin-bottom: 18px; }\n.hero h1 { margin: 0 0 18px; font-size: 36px; line-height: 1.3; letter-spacing: -0.3px; }\n.hero p.sub { margin: 0 auto; max-width: 580px; font-size: 17px; color: #bfdbfe; }\n.hero img { width: 100%; max-width: 720px; height: auto; margin: 36px auto 0; display: block; border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }\n.meta { display: flex; gap: 14px; justify-content: center; margin-top: 20px; font-size: 13px; color: #93c5fd; flex-wrap: wrap; }\n.meta span::before { content: \"\u00b7\"; margin-right: 14px; color: #1e3a8a; }\n.meta span:first-child::before { content: \"\"; margin: 0; }\narticle { background: var(--color-bg-card); margin-top: -36px; padding: 44px 28px; border-radius: 14px; box-shadow: 0 2px 18px rgba(0,0,0,0.06); }\narticle p { margin: 0 0 18px; }\nh2 { font-size: 28px; line-height: 1.35; letter-spacing: -0.3px; margin: 48px 0 18px; padding-bottom: 10px; border-bottom: 2px solid var(--color-primary); }\nh2:first-of-type { margin-top: 8px; }\nh3 { font-size: 21px; line-height: 1.4; margin: 30px 0 12px; color: var(--color-primary); }\ncode { background: #f1f5f9; color: #0f172a; padding: 2px 6px; border-radius: 4px; font-family: 'SFMono-Regular', Menlo, Consolas, monospace; font-size: 0.92em; }\npre { background: #0f172a; color: #e2e8f0; padding: 18px 20px; border-radius: 10px; overflow-x: auto; font-size: 14.5px; line-height: 1.65; margin: 18px 0; }\npre code { background: transparent; color: inherit; padding: 0; }\nul, ol { margin: 0 0 18px; padding-left: 24px; }\nli { margin-bottom: 8px; }\nstrong { color: #0f172a; }\n.databox { background: #eff6ff; border-left: 4px solid var(--color-primary); padding: 18px 20px; border-radius: 6px; margin: 22px 0; }\n.databox p { margin: 0 0 8px; }\n.databox p:last-child { margin: 0; }\n.databox strong { color: var(--color-primary); }\n.warnbox { background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); border-left: 4px solid #d97706; padding: 18px 20px; border-radius: 6px; margin: 22px 0; }\n.warnbox strong { color: #92400e; }\n.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 22px 0; }\ntable { width: 100%; border-collapse: collapse; font-size: 15px; background: var(--color-bg-card); }\nth, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; vertical-align: top; }\nth { background: #f1f5f9; font-weight: 700; color: #0f172a; }\ntd:first-child, th:first-child { font-weight: 700; }\n.cta { background: linear-gradient(135deg, #336791 0%, #60a5fa 100%); color: #fff; padding: 30px 24px; border-radius: 12px; margin-top: 44px; text-align: center; }\n.cta h3 { color: #fff; margin: 0 0 10px; }\n.cta p { margin: 0; color: #dbeafe; }\n.series-nav { background: #eff6ff; padding: 18px 22px; border-radius: 10px; margin-top: 24px; font-size: 14.5px; color: var(--color-text-muted); }\n.series-nav strong { color: var(--color-primary); }\n@media (max-width: 480px) {\n  .hero { padding: 52px 18px 44px; }\n  .hero h1 { font-size: 26px; }\n  .hero p.sub { font-size: 15px; }\n  article { padding: 28px 18px; border-radius: 10px; }\n  h2 { font-size: 22px; }\n  h3 { font-size: 18px; }\npre { font-size: 13px; padding: 14px 16px; }\n}\n@media (max-width: 560px) {\n  .tablewrap table, .tablewrap thead, .tablewrap tbody, .tablewrap tr, .tablewrap th, .tablewrap td { display: block; width: auto; }\n  .tablewrap thead { display: none; }\n  .tablewrap tr { margin: 0 0 14px; border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }\n  .tablewrap td { border: none; border-bottom: 1px solid #f1f5f9; padding: 9px 14px; }\n  .tablewrap td:first-child { background: #eff6ff; font-weight: 800; font-size: 15.5px; }\n  .tablewrap td:last-child { border-bottom: none; }\n  .tablewrap td[data-label]::before { content: attr(data-label) \" \u2014 \"; font-weight: 700; color: var(--color-primary); }\n}\n<\/style>\n<header class=\"hero\">\n  <span class=\"badge\">\ud30c\uc774\uc36c \uad50\uc7ac \u00b7 13\ud3b8 \/ 27\ud3b8<\/span>\n  <h1>\ud30c\uc774\uc36c \ud30c\uc77c \uc77d\uae30\u00b7\uc4f0\uae30<\/h1>\n  <p class=\"sub\">\ub514\uc2a4\ud06c\uc5d0 \uc800\uc7a5\ud558\uace0 \ubd88\ub7ec\uc624\ub294 \ubc95. \uc790\ub3d9\ud654 \uc2a4\ud06c\ub9bd\ud2b8\uc758 \uc591 \ub2e4\ub9ac.<\/p>\n  <div class=\"meta\"><span>\uae30\ucd08<\/span><span>\uc77d\ub294 \uc2dc\uac04 7\ubd84<\/span><span>2026-05-13<\/span><\/div>\n  <img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/hero-211.jpg\" alt=\"open with \ubb38\uc73c\ub85c \ud30c\uc77c \uc77d\uae30\u00b7\uc4f0\uae30\u00b7JSON \ub2e4\ub8e8\ub294 \ucf54\ub4dc \ud654\uba74\">\n<\/header>\n\n<div class=\"container\">\n<article>\n\n<p>\uc9c0\uae08\uae4c\uc9c0 \uc6b0\ub9ac \ucf54\ub4dc\uc758 \ubaa8\ub4e0 \uacb0\uacfc\ub294 <strong>\ucc3d\uc744 \ub2eb\uc73c\uba74 \uc0ac\ub77c\uc84c\uc2b5\ub2c8\ub2e4<\/strong>. \ubcc0\uc218\uc5d0 \ub2f4\uc740 \ud559\uc0dd 30\uba85 \ub370\uc774\ud130, \ubd84\uc11d \uacb0\uacfc, \uc0ac\uc6a9\uc790 \ub85c\uadf8 \u2014 \ub2e4 \uba54\ubaa8\ub9ac\uc5d0\ub9cc. \ub514\uc2a4\ud06c\uc5d0 \uc800\uc7a5\ud558\uc9c0 \uc54a\uc73c\uba74 \uadf8 \ub2e4\uc74c\uc5d0 \uc4f8 \uc218 \uc5c6\uc8e0. 13\ud3b8\uc774 \uadf8\ub798\uc11c \ud30c\uc774\uc36c\uc744 &#8220;\uc2a4\ud06c\ub9bd\ud2b8&#8221; \uc5d0\uc11c &#8220;\uc2e4\uc81c \ub3c4\uad6c&#8221; \ub85c \ud55c \ub2e8\uacc4 \uc62c\ub9ac\ub294 \ucc55\ud130\uc785\ub2c8\ub2e4. \uc785\ubb38\uc774 \ub05d\ub098\uace0 <strong>\uae30\ucd08<\/strong> \ubb36\uc74c\uc758 \uc2dc\uc791.<\/p>\n\n<p>13\ud3b8\uc744 \ub9c8\uce58\uba74 \u2460 <code>open<\/code> \uc758 \ubaa8\ub4dc 6\uac00\uc9c0 \u2461 <code>with<\/code> \ucee8\ud14d\uc2a4\ud2b8 \ub9e4\ub2c8\uc800 \u2462 \ud55c \uc904\uc529 vs \ud1b5\uc9f8\ub85c \uc77d\uae30 \u2463 CSV\u00b7JSON \uac19\uc774 \uc790\uc8fc \ub9cc\ub098\ub294 \ud615\uc2dd \u2464 <code>pathlib<\/code> \uc758 \ud604\ub300\uc2dd \uc0ac\uc6a9\ubc95 \u2014 5\uac00\uc9c0\uac00 \uc190\uc5d0 \uc775\uc2b5\ub2c8\ub2e4.<\/p>\n\n<h2>open \uc758 6\uac00\uc9c0 \ubaa8\ub4dc<\/h2>\n\n<p><code>open(\ud30c\uc77c\uacbd\ub85c, \ubaa8\ub4dc)<\/code> \uac00 \uae30\ubcf8 \ud615\ud0dc. \ub450 \ubc88\uc9f8 \uc778\uc790\uac00 \ubb34\uc5c7\uc744 \ud560\uc9c0 \uc815\ud569\ub2c8\ub2e4.<\/p>\n\n<div class=\"tablewrap\">\n<table>\n  <thead>\n    <tr><th>\ubaa8\ub4dc<\/th><th>\uc758\ubbf8<\/th><th>\ud30c\uc77c \uc5c6\uc73c\uba74<\/th><th>\uae30\uc874 \ub0b4\uc6a9<\/th><\/tr>\n  <\/thead>\n  <tbody>\n    <tr><td><code>\"r\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\uc77d\uae30 (\uae30\ubcf8\uac12)<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">FileNotFoundError<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\">\uc720\uc9c0<\/td><\/tr>\n    <tr><td><code>\"w\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\uc4f0\uae30<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">\uc0dd\uc131<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\"><strong>\ub36e\uc5b4\uc500!<\/strong><\/td><\/tr>\n    <tr><td><code>\"a\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\ucd94\uac00<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">\uc0dd\uc131<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\">\ub05d\uc5d0 \uc774\uc5b4\ubd99\uc784<\/td><\/tr>\n    <tr><td><code>\"x\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\uc0dd\uc131 \uc804\uc6a9<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">\uc0dd\uc131<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\">\uc788\uc73c\uba74 FileExistsError<\/td><\/tr>\n    <tr><td><code>\"rb\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\ubc14\uc774\ub108\ub9ac \uc77d\uae30<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">FileNotFoundError<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\">\uc720\uc9c0 (\uc774\ubbf8\uc9c0\u00b7zip \ub4f1)<\/td><\/tr>\n    <tr><td><code>\"r+\"<\/code><\/td><td data-label=\"\uc758\ubbf8\">\uc77d\uae30+\uc4f0\uae30<\/td><td data-label=\"\ud30c\uc77c \uc5c6\uc73c\uba74\">FileNotFoundError<\/td><td data-label=\"\uae30\uc874 \ub0b4\uc6a9\">\uc720\uc9c0\u00b7\uc218\uc815<\/td><\/tr>\n  <\/tbody>\n<\/table>\n<\/div>\n\n<div class=\"warnbox\">\n  <strong>\u26a0\ufe0f &#8220;w&#8221; \uc758 \ud568\uc815.<\/strong> <code>open(\"important.txt\", \"w\")<\/code> \ub294 \uae30\uc874 \ub0b4\uc6a9\uc744 <strong>\uc989\uc2dc 0\ubc14\uc774\ud2b8\ub85c \ub0a0\ub9bd\ub2c8\ub2e4<\/strong>. \ucd94\uac00\ud558\ub824\uba74 \ubc18\ub4dc\uc2dc <code>\"a\"<\/code>. \uc2e4\uc218\ub85c <code>\"w\"<\/code> \ub85c \uc5f4\uace0 \uadf8\ub0e5 \ub2eb\uae30\ub9cc \ud574\ub3c4 \ud30c\uc77c\uc774 \ube44\uac8c \ub3fc\uc694. \uc785\ubb38\uc790 \uac00\uc7a5 \ud754\ud55c \uc0ac\uace0 1\ubc88.\n<\/div>\n\n<h2>with \ubb38 \u2014 \uc790\ub3d9 close \uc758 \ub9c8\ubc95<\/h2>\n\n<p>\ud30c\uc77c\uc744 \uc5f4\uc5c8\uc73c\uba74 \ub2eb\uc544\uc57c \ud569\ub2c8\ub2e4. \uc548 \ub2eb\uc73c\uba74 \ub2e4\ub978 \ud504\ub85c\uadf8\ub7a8\uc774 \ubabb \uc4f0\uac70\ub098, \ubcc0\uacbd\uc774 \ub514\uc2a4\ud06c\uc5d0 \uc548 \ubc18\uc601\ub418\uac70\ub098, \uc6b4\uc601\uccb4\uc81c \ud578\ub4e4\uc774 \uc0c8\uc694. <strong><code>with<\/code> \uac00 \uc774\uac78 \uc790\ub3d9\uc73c\ub85c<\/strong>.<\/p>\n\n<pre><code># \uc61b\ub0a0 \ubc29\uc2dd (\uc2e4\uc218 \uac00\ub2a5)\nf = open(\"data.txt\")\ntext = f.read()\nf.close()                # \ube60\ub728\ub9ac\uac70\ub098 \uc5d0\ub7ec \ub098\uba74 \uc548 \ub2eb\ud798\n\n# \ud604\ub300 \ubc29\uc2dd (\uad8c\uc7a5)\nwith open(\"data.txt\") as f:\n    text = f.read()\n# \ub4e4\uc5ec\uc4f0\uae30 \ub05d\ub098\uba74 \uc790\ub3d9 close \u2014 \uc608\uc678\uac00 \ub098\ub3c4 \ubcf4\uc7a5<\/code><\/pre>\n\n<p><code>with<\/code> \ub294 <strong>\ucee8\ud14d\uc2a4\ud2b8 \ub9e4\ub2c8\uc800<\/strong>\ub77c\ub294 \uace0\uae09 \uac1c\ub150\uc758 \ud45c\uba74\uc785\ub2c8\ub2e4. \ub4e4\uc5ec\uc4f0\uae30 \ube14\ub85d\uc744 \ube60\uc838\ub098\uac00\ub294 \uc21c\uac04 \u2014 \uc815\uc0c1\uc774\ub4e0 \uc608\uc678\ub4e0 \u2014 \uc57d\uc18d\ud55c \uc815\ub9ac \uc791\uc5c5\uc774 \uc2e4\ud589\ub3fc\uc694. 12\ud3b8 try-finally \uc758 \uc808\uc81c\ub41c \ubc84\uc804.<\/p>\n\n<h2>\uc77d\uae30 \u2014 \ud1b5\uc9f8\ub85c\u00b7\ud55c \uc904\uc529\u00b7\ubc18\ubcf5<\/h2>\n\n<pre><code># 1) \ud1b5\uc9f8\ub85c \ud55c \ubb38\uc790\uc5f4\ub85c\nwith open(\"poem.txt\", encoding=\"utf-8\") as f:\n    text = f.read()         # \uc804\uccb4 \u2014 \uc791\uc740 \ud30c\uc77c\uc5d0\ub9cc\n\n# 2) \uc904 \ub2e8\uc704 \ub9ac\uc2a4\ud2b8\nwith open(\"poem.txt\", encoding=\"utf-8\") as f:\n    lines = f.readlines()   # ['\uccab \uc904\\n', '\ub458\uc9f8 \uc904\\n', ...]\n\n# 3) \ud55c \uc904\uc529 \uc21c\ud68c \u2014 \ud070 \ud30c\uc77c\uc5d0\ub3c4 \uc548\uc804 (\uba54\ubaa8\ub9ac \ud55c \uc904\ub9cc)\nwith open(\"huge.log\", encoding=\"utf-8\") as f:\n    for line in f:\n        if \"ERROR\" in line:\n            print(line.rstrip())<\/code><\/pre>\n\n<p>3\ubc88\uc774 \uc2e4\ubb34 \uc815\uacf5\ubc95. 100GB \ub85c\uadf8\ub3c4 \uba54\ubaa8\ub9ac \ubd80\ub2f4 \uc5c6\uc774 \ud55c \uc904\uc529 \ud750\ub985\ub2c8\ub2e4. <code>rstrip()<\/code> \uc740 \uc904 \ub05d\uc758 <code>\\n<\/code> \uc81c\uac70.<\/p>\n\n<div class=\"databox\">\n  <p><strong>\ud83d\udccc encoding=&#8221;utf-8&#8243; \uc740 \uac70\uc758 \ud56d\uc0c1 \uba85\uc2dc<\/strong><\/p>\n  <p>\uc708\ub3c4\uc6b0\uc758 \uae30\ubcf8 \uc778\ucf54\ub529(cp949)\u00b7\ub9e5\/\ub9ac\ub205\uc2a4(utf-8) \uac00 \ub2ec\ub77c \ud55c\uae00 \ud30c\uc77c\uc774 OS \uc0ac\uc774\ub97c \uc624\uac08 \ub54c \uae68\uc9d1\ub2c8\ub2e4. <code>encoding=\"utf-8\"<\/code> \ud55c \uc904\ub85c \ubaa8\ub4e0 \ud658\uacbd\uc5d0\uc11c \uac19\uc740 \ub3d9\uc791. 2026\ub144 \uae30\uc900 utf-8 \uc774 \ud45c\uc900\uc785\ub2c8\ub2e4.<\/p>\n<\/div>\n\n<h2>\uc4f0\uae30 \u2014 write\u00b7writelines\u00b7print \ub9ac\ub2e4\uc774\ub809\ud2b8<\/h2>\n\n<pre><code># \ud55c \ubb38\uc790\uc5f4 \uc4f0\uae30 (\ub36e\uc5b4\uc4f0\uae30)\nwith open(\"hello.txt\", \"w\", encoding=\"utf-8\") as f:\n    f.write(\"\uc548\ub155\\n\ud30c\uc774\uc36c\\n\")\n\n# \uc5ec\ub7ec \uc904 \ud55c\uaebc\ubc88\uc5d0\nlines = [\"\uc904 1\\n\", \"\uc904 2\\n\", \"\uc904 3\\n\"]\nwith open(\"multi.txt\", \"w\", encoding=\"utf-8\") as f:\n    f.writelines(lines)        # \\n \uc548 \ubd99\uc5ec\uc90c, \ubcf8\uc778\uc774 \ud3ec\ud568\n\n# print \ub85c \ud30c\uc77c\uc5d0 \uc4f0\uae30 (\ub35c \uc77c\ubc18\uc801\uc774\uc9c0\ub9cc \uae54\ub054)\nwith open(\"log.txt\", \"a\", encoding=\"utf-8\") as f:\n    print(f\"[2026-05-13] \uc791\uc5c5 \uc644\ub8cc\", file=f)<\/code><\/pre>\n\n<p><code>write<\/code> \ub294 \uc904\ubc14\uafc8\uc744 \uc790\ub3d9\uc73c\ub85c \uc548 \ubd99\uc785\ub2c8\ub2e4. \ub9e4 \uc904 \ub05d\uc5d0 <code>\\n<\/code> \ud544\uc694. <code>print(..., file=f)<\/code> \ud328\ud134\uc740 print \uc758 \uc904\ubc14\uafc8\uc744 \uadf8\ub300\ub85c \ud65c\uc6a9 \u2014 \ub85c\uadf8 \ud30c\uc77c \uc791\uc131\uc5d0\uc11c \uc790\uc8fc \uc4f0\uc5ec\uc694.<\/p>\n\n<h2>CSV\u00b7JSON \u2014 \uc790\uc8fc \ub9cc\ub098\ub294 \ub450 \ud615\uc2dd<\/h2>\n\n<h3>CSV \u2014 \ucf64\ub9c8\ub85c \uad6c\ubd84\ub41c \ud45c<\/h3>\n\n<pre><code>import csv\n\n# \uc4f0\uae30\nwith open(\"scores.csv\", \"w\", encoding=\"utf-8\", newline=\"\") as f:\n    w = csv.writer(f)\n    w.writerow([\"\uc774\ub984\", \"\uc810\uc218\"])\n    w.writerow([\"\uc900\uc131\", 88])\n    w.writerow([\"\uc218\ubbfc\", 92])\n\n# \uc77d\uae30 \u2014 \uccab \uc904\uc744 \ud0a4\ub85c (DictReader \uad8c\uc7a5)\nwith open(\"scores.csv\", encoding=\"utf-8\") as f:\n    for row in csv.DictReader(f):\n        print(f\"{row['\uc774\ub984']}: {row['\uc810\uc218']}\")\n# \uc900\uc131: 88\n# \uc218\ubbfc: 92<\/code><\/pre>\n\n<p><code>newline=\"\"<\/code> \ub294 csv \ubaa8\ub4c8\uc758 \uc57d\uc18d \u2014 \ube7c\uba74 \uc708\ub3c4\uc6b0\uc5d0\uc11c \uc904 \uc0ac\uc774\uc5d0 \ube48 \uc904\uc774 \uc0dd\uae41\ub2c8\ub2e4.<\/p>\n\n<h3>JSON \u2014 \uc124\uc815\u00b7API \ub2e8\uace8<\/h3>\n\n<pre><code>import json\n\n# \uc800\uc7a5\ndata = {\"users\": [{\"name\": \"\uc900\uc131\", \"age\": 30}], \"version\": 2}\nwith open(\"config.json\", \"w\", encoding=\"utf-8\") as f:\n    json.dump(data, f, ensure_ascii=False, indent=2)\n\n# \uc77d\uae30\nwith open(\"config.json\", encoding=\"utf-8\") as f:\n    cfg = json.load(f)\nprint(cfg[\"users\"][0][\"name\"])    # \uc900\uc131<\/code><\/pre>\n\n<p>\ud55c\uae00\uc774 \ub4e4\uc5b4\uac00\uba74 <code>ensure_ascii=False<\/code> \ub97c \uc78a\uc9c0 \ub9c8\uc138\uc694. \uc548 \uadf8\ub7ec\uba74 <code>\"\uc900\uc131\"<\/code> \uac19\uc740 \uc720\ub2c8\ucf54\ub4dc \uc774\uc2a4\ucf00\uc774\ud504\ub85c \uc800\uc7a5\ub429\ub2c8\ub2e4.<\/p>\n\n<h3>pathlib \u2014 \uacbd\ub85c\uc758 \ud604\ub300\uc2dd \ub2e4\ub8e8\uae30<\/h3>\n\n<pre><code>from pathlib import Path\n\np = Path(\"data\") \/ \"scores.csv\"      # OS \ubb34\uad00\ud55c \uacbd\ub85c \ud569\uc131\np.parent.mkdir(parents=True, exist_ok=True)  # \ud3f4\ub354 \uc5c6\uc73c\uba74 \uc0dd\uc131\np.write_text(\"\uc774\ub984,\uc810\uc218\\n\uc900\uc131,88\\n\", encoding=\"utf-8\")\ntext = p.read_text(encoding=\"utf-8\")\n\n# \ub514\ub809\ud1a0\ub9ac \uc21c\ud68c\nfor f in Path(\"logs\").glob(\"*.log\"):\n    print(f.name, f.stat().st_size)<\/code><\/pre>\n\n<p><code>os.path<\/code> \ubcf4\ub2e4 \uc9e7\uace0 OS \ucc28\uc774\ub97c \uc790\ub3d9 \ucc98\ub9ac. 2026\ub144 \uc2e0\uaddc \ucf54\ub4dc\ub294 \uac70\uc758 <code>pathlib<\/code> \uc785\ub2c8\ub2e4.<\/p>\n\n<p>\ub2e4\uc74c \ubbf8\uc158 \u2014 REPL \uc5d0\uc11c: \u2460 <code>diary.txt<\/code> \uc5d0 \uc624\ub298 \ub0a0\uc9dc\uc640 \ud55c \uc904\uc744 \ucd94\uac00(append) \u2461 CSV \uc5d0 \ubcf8\uc778 \ud55c \uc8fc \ub9e4\ucd9c 7\uc77c\uce58 \uc800\uc7a5 \ud6c4 \ud3c9\uade0 \uacc4\uc0b0\ud574 \ucd9c\ub825 \u2462 JSON \ud30c\uc77c\uc744 \uc77d\uace0 \ud55c \ud0a4\ub9cc \ubc14\uafd4 \ub2e4\uc2dc \uc800\uc7a5.<\/p>\n\n<div class=\"cta\">\n  <h3>\ub2e4\uc74c \ud3b8 \ubbf8\ub9ac\ubcf4\uae30<\/h3>\n  <p>14\ud3b8 \u2014 &#8220;\ud30c\uc774\uc36c \ud074\ub798\uc2a4 \uc785\ubb38&#8221;: <code>class<\/code>\u00b7<code>__init__<\/code>\u00b7\uba54\uc11c\ub4dc\u00b7\uc18d\uc131. \uac1d\uccb4\uc9c0\ud5a5\uc758 \uccab \ubc1c\uac78\uc74c.<\/p>\n<\/div>\n\n<div class=\"series-nav\">\n  <strong>\ud83d\udcda 27\ud3b8 \ud30c\uc774\uc36c \uad50\uc7ac \uc2dc\ub9ac\uc988 \u2014 13\/27\ud3b8<\/strong><br>\n  \u2190 12\ud3b8 &#8220;\uc608\uc678 \ucc98\ub9ac&#8221; \u00b7 \ub2e4\uc74c: 14\ud3b8 &#8220;\ud074\ub798\uc2a4 \uc785\ubb38&#8221;\n<\/div>\n\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>open\u00b7with\u00b7read\/write\u00b7CSV\u00b7JSON\u00b7pathlib \uae4c\uc9c0. 27\ud3b8 \uad50\uc7ac 13\ud3b8.<\/p>\n","protected":false},"author":1,"featured_media":592,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":1,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":619,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/226\/revisions\/619"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media\/592"}],"wp:attachment":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}