{"id":3137,"date":"2026-11-20T22:45:47","date_gmt":"2026-11-20T13:45:47","guid":{"rendered":"https:\/\/danlabs.kr\/?p=3137"},"modified":"2026-11-20T22:45:47","modified_gmt":"2026-11-20T13:45:47","slug":"python-csv-dictreader-extra-missing-fields","status":"publish","type":"post","link":"https:\/\/danlabs.kr\/?p=3137","title":{"rendered":"Python csv.DictReader\ub85c CSV \uc77d\uae30, \uc5f4 \ub204\ub77d\uacfc \ucd08\uacfc\ub97c \uad6c\ubd84\ud574\uc694"},"content":{"rendered":"<p>CSV\ub97c \uc27c\ud45c\ub85c \uc798\ub77c \uc77d\uc73c\uba74 \ub530\uc634\ud45c \uc548\uc758 \uc27c\ud45c\uc640 \uc904\ubc14\uafc8\ubd80\ud130 \ud2c0\uc5b4\uc838\uc694. <code>csv.DictReader<\/code>\ub97c \uc4f0\uba74 \ud5e4\ub354 \uc774\ub984\uc73c\ub85c \uac12\uc744 \uaebc\ub0bc \uc218 \uc788\uc9c0\ub9cc, \uc5f4 \uc218\uac00 \ub9de\ub294\uc9c0\uae4c\uc9c0 \uc790\ub3d9\uc73c\ub85c \uac70\ubd80\ud574 \uc8fc\uc9c0\ub294 \uc54a\uc544\uc694. \uac00\uc838\uc624\uae30 \ucf54\ub4dc\ub294 \ud30c\uc2f1\uacfc \ub370\uc774\ud130 \uac80\uc99d\uc744 \ub098\ub220 \uc791\uc131\ud558\ub294 \uac8c \uc548\uc804\ud574\uc694.[1]<\/p>\n<figure><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-inline1.jpg\" alt=\"DictReader \ud30c\uc2f1 \ub4a4 \uc5f4 \uc218\uc640 \uc5c5\ubb34 \uaddc\uce59\uc744 \uac80\uc0ac\ud558\ub294 \ud750\ub984 \ub3c4\uc2dd\" width=\"1280\" height=\"720\"><figcaption>\ub0b4\uc6a9 \uc774\ud574\ub97c \ub3d5\uae30 \uc704\ud574 \uc0dd\uc131\ud55c \uac1c\ub150 \uc774\ubbf8\uc9c0\uc608\uc694. \uc2e4\uc81c \uc81c\ud488 \uc0ac\uc9c4\uc774\ub098 \uc2e4\ud589 \ud654\uba74 \ucea1\ucc98\uac00 \uc544\ub2c8\uc5d0\uc694.<\/figcaption><\/figure>\n<h2>\ud5e4\ub354\ub294 \ud0a4\uac00 \ub418\uace0 \uac12\uc740 \ubb38\uc790\uc5f4\ub85c \ub4e4\uc5b4\uc640\uc694<\/h2>\n<p><code>fieldnames<\/code>\ub97c \ub530\ub85c \uc9c0\uc815\ud558\uc9c0 \uc54a\uc73c\uba74 \uccab \ud589\uc744 \ud5e4\ub354\ub85c \uc4f0\uace0 \uacb0\uacfc\uc5d0\uc11c \uc81c\uc678\ud574\uc694. \uc9c1\uc811 \uc9c0\uc815\ud558\uba74 \uccab \ud589\ub3c4 \ub370\uc774\ud130\uc5d0 \ud3ec\ud568\ub3fc\uc694. \ud5e4\ub354\uac00 \uc788\ub294 \ud30c\uc77c\uc778\uc9c0 \uc54c\uace0 \uc788\uc744 \ub54c \ub450 \ubc29\uc2dd\uc744 \uad6c\ubd84\ud574\uc57c \ud574\uc694. \uc77c\ubc18\uc801\uc778 <code>csv.reader<\/code>\ub294 \uae30\ubcf8\uc801\uc73c\ub85c \uc790\ub3d9 \uc790\ub8cc\ud615 \ubcc0\ud658\uc744 \ud558\uc9c0 \uc54a\uc73c\ubbc0\ub85c \uc218\ub7c9\ucc98\ub7fc \ubcf4\uc774\ub294 \uac12\ub3c4 \ubb38\uc790\uc5f4\ub85c \uc77d\ud600\uc694. \uc544\ub798 \uc608\uc81c\uc758 <code>&#x27;2&#x27;<\/code>\ub3c4 \uc815\uc218 \ubcc0\ud658 \uc804\uc758 \uac12\uc774\uc5d0\uc694.[1]<\/p>\n<p>\ud30c\uc77c\uc744 \uc5f4 \ub54c\ub294 <code>open(&#x27;input.csv&#x27;, encoding=&#x27;utf-8&#x27;, newline=&#x27;&#x27;)<\/code>\ucc98\ub7fc \uc778\ucf54\ub529\uacfc \uc904\ubc14\uafc8 \ucc98\ub9ac\ub97c \uba85\uc2dc\ud574\uc694. <code>utf-8<\/code>\uc740 \uc774 \uc608\uc81c\uc5d0\uc11c \uc815\ud55c \ud30c\uc77c \uc778\ucf54\ub529\uc774\uace0, \ub2e4\ub978 \uc778\ucf54\ub529\uc758 \ud30c\uc77c\uc740 \uadf8\uc5d0 \ub9de\ucdb0\uc57c \ud574\uc694. Python \ubb38\uc11c\ub294 CSV \ud30c\uc77c \uac1d\uccb4\ub97c <code>newline=&#x27;&#x27;<\/code>\ub85c \uc5f4\ub3c4\ub85d \uc548\ub0b4\ud574\uc694. \uc544\ub798\uc5d0\uc11c\ub294 \ud30c\uc77c\uc744 \ub9cc\ub4e4\uc9c0 \uc54a\uace0 <code>StringIO<\/code>\ub85c \uac19\uc740 \ud615\ud0dc\uc758 \uc785\ub825\uc744 \uc81c\uacf5\ud574\uc694.[1]<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-inline2.jpg\" alt=\"\uc5f4 \ucd08\uacfc\ub294 restkey \ub9ac\uc2a4\ud2b8, \ubd80\uc871\uc740 restval\ub85c \ucc98\ub9ac\ud558\ub294 DictReader \ub3c4\uc2dd\" width=\"1280\" height=\"720\"><figcaption>\ub0b4\uc6a9 \uc774\ud574\ub97c \ub3d5\uae30 \uc704\ud574 \uc0dd\uc131\ud55c \uac1c\ub150 \uc774\ubbf8\uc9c0\uc608\uc694. \uc2e4\uc81c \uc81c\ud488 \uc0ac\uc9c4\uc774\ub098 \uc2e4\ud589 \ud654\uba74 \ucea1\ucc98\uac00 \uc544\ub2c8\uc5d0\uc694.<\/figcaption><\/figure>\n<h2>\uc5f4\uc774 \ub354 \ub9ce\uc744 \ub54c\uc640 \ubaa8\uc790\ub784 \ub54c\ub97c \ub530\ub85c \uc7a1\uc544\uc694<\/h2>\n<p><code>DictReader<\/code>\ub294 \ud5e4\ub354\ubcf4\ub2e4 \ub9ce\uc740 \uac12\uc744 <code>restkey<\/code>\uac00 \uc9c0\uc815\ud55c \ud0a4 \uc544\ub798 \ub9ac\uc2a4\ud2b8\ub85c \ubaa8\uc544\uc694. \ubd80\uc871\ud55c \ud544\ub4dc\ub294 <code>restval<\/code>\ub85c \ucc44\uc6cc\uc694. \uc544\ub798 \ucf54\ub4dc\ub294 \ucd08\uacfc \uac12\uc744 <code>_extra<\/code>, \ub204\ub77d \uac12\uc744 <code>None<\/code>\uc73c\ub85c \uad6c\ubcc4\ud574\uc694. \uc2e4\uc81c \uc785\ub825 \ud5e4\ub354\uc5d0 <code>_extra<\/code>\ub77c\ub294 \uc774\ub984\uc774 \uc5c6\ub2e4\ub294 \uc804\uc81c\uc758 \uc608\uc81c\uc608\uc694.[1]<\/p>\n<p>\ub2e4\uc74c \ucf54\ub4dc\ub97c <code>read_csv.py<\/code>\ub85c \uc800\uc7a5\ud574 <code>python3 read_csv.py<\/code>\ub85c \uc2e4\ud589\ud558\uba74 \ub3fc\uc694. \ub530\uc634\ud45c \uc548 \uc27c\ud45c\u00b7\uc904\ubc14\uafc8, \uc5f4 \ub204\ub77d, \uc5f4 \ucd08\uacfc, \ube48 \ubb38\uc790\uc5f4\uc744 \ud55c \uc785\ub825\uc5d0 \ub123\uc5c8\uc5b4\uc694.<\/p>\n<pre><code>import csv\nfrom io import StringIO\nimport sys\n\ntext = (&#x27;name,qty,memo\\n&#x27;\n        &#x27;&quot;USB, \ucf00\uc774\ube14&quot;,2,&quot;\uccab \uc904\\n\ub458\uc9f8 \uc904&quot;\\n&#x27;\n        &#x27;\ub9c8\uc6b0\uc2a4,1\\n&#x27;\n        &#x27;\ud0a4\ubcf4\ub4dc,3,\uc815\uc0c1,\ucd94\uac00\\n&#x27;\n        &#x27;\uc2a4\ud0e0\ub4dc,1,\\n&#x27;)\nreader = csv.DictReader(StringIO(text, newline=&#x27;&#x27;),\n                        restkey=&#x27;_extra&#x27;, restval=None)\nfor record_no, row in enumerate(reader, start=1):\n    print(f&#x27;\ub808\ucf54\ub4dc {record_no}, \ub05d\ub09c \ubb3c\ub9ac \uc904 {reader.line_num}&#x27;)\n    if row.get(&#x27;_extra&#x27;) is not None:\n        print(&#x27;\ucd08\uacfc:&#x27;, row[&#x27;_extra&#x27;])\n        continue\n    missing = [key for key in reader.fieldnames if row[key] is None]\n    if missing:\n        print(&#x27;\ub204\ub77d:&#x27;, missing)\n        continue\n    print(repr(row[&#x27;name&#x27;]), repr(row[&#x27;qty&#x27;]), repr(row[&#x27;memo&#x27;]))\n    print(&#x27;qty \uc790\ub8cc\ud615:&#x27;, type(row[&#x27;qty&#x27;]).__name__)\nassert reader.line_num == 6\nprint(&#x27;Python:&#x27;, sys.version.split()[0])<\/code><\/pre>\n<p>Linux\uc758 Python 3.14.7\uc5d0\uc11c \uc774 \ucf54\ub4dc\ub97c \uc2e4\ud589\ud55c \ucd9c\ub825\uc740 \ub2e4\uc74c\uacfc \uac19\uc544\uc694. \uc124\uba85\uc5d0 \uc0ac\uc6a9\ud55c \uc628\ub77c\uc778 \uacf5\uc2dd \ubb38\uc11c\ub294 \uc870\ud68c \ub2f9\uc2dc Python 3.15.2 \ubb38\uc11c\uc774\uba70, \uc5ec\uae30 \uc801\uc740 \uc2e4\ud589 \uacb0\uacfc\ub294 \uc544\ub798 \ubc84\uc804\uc5d0\uc11c \uc5bb\uc5c8\uc5b4\uc694.<\/p>\n<pre><code>\ub808\ucf54\ub4dc 1, \ub05d\ub09c \ubb3c\ub9ac \uc904 3\n&#x27;USB, \ucf00\uc774\ube14&#x27; &#x27;2&#x27; &#x27;\uccab \uc904\\n\ub458\uc9f8 \uc904&#x27;\nqty \uc790\ub8cc\ud615: str\n\ub808\ucf54\ub4dc 2, \ub05d\ub09c \ubb3c\ub9ac \uc904 4\n\ub204\ub77d: [&#x27;memo&#x27;]\n\ub808\ucf54\ub4dc 3, \ub05d\ub09c \ubb3c\ub9ac \uc904 5\n\ucd08\uacfc: [&#x27;\ucd94\uac00&#x27;]\n\ub808\ucf54\ub4dc 4, \ub05d\ub09c \ubb3c\ub9ac \uc904 6\n&#x27;\uc2a4\ud0e0\ub4dc&#x27; &#x27;1&#x27; &#x27;&#x27;\nqty \uc790\ub8cc\ud615: str\nPython: 3.14.7<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-inline3.jpg\" alt=\"\ub808\ucf54\ub4dc \uc218\uc640 \uc785\ub825 \ubb3c\ub9ac \uc904 \uc218\ub97c \uad6c\ubd84\ud558\ub294 line_num \uc124\uba85 \ub3c4\uc2dd\" width=\"1280\" height=\"720\"><figcaption>\ub0b4\uc6a9 \uc774\ud574\ub97c \ub3d5\uae30 \uc704\ud574 \uc0dd\uc131\ud55c \uac1c\ub150 \uc774\ubbf8\uc9c0\uc608\uc694. \uc2e4\uc81c \uc81c\ud488 \uc0ac\uc9c4\uc774\ub098 \uc2e4\ud589 \ud654\uba74 \ucea1\ucc98\uac00 \uc544\ub2c8\uc5d0\uc694.<\/figcaption><\/figure>\n<h2>\ub808\ucf54\ub4dc \ubc88\ud638\uc640 \ubb3c\ub9ac\uc801\uc778 \uc904 \ubc88\ud638\ub294 \ub2ec\ub77c\uc694<\/h2>\n<p>\uccab \ub370\uc774\ud130\uc758 \uba54\ubaa8\ub294 \ub530\uc634\ud45c \uc548\uc5d0 \uc904\ubc14\uafc8\uc744 \ud3ec\ud568\ud574\uc694. \ud30c\uc11c\ub294 \uc774\ub97c \ud558\ub098\uc758 \uac12\uc73c\ub85c \uc77d\uc5c8\uc9c0\ub9cc \uc785\ub825\uc5d0\uc11c\ub294 \ud5e4\ub354\ub97c \ud3ec\ud568\ud574 3\uac1c \ubb3c\ub9ac \uc904\uc744 \uc77d\uc5c8\uc5b4\uc694. <code>reader.line_num<\/code>\uc740 \ubc18\ud658\ud55c \ub808\ucf54\ub4dc \uc218\uac00 \uc544\ub2c8\ub77c \uc6d0\ubcf8\uc5d0\uc11c \uc77d\uc740 \uc904 \uc218\uc608\uc694. \ub530\ub77c\uc11c \uc624\ub958 \ubcf4\uace0\uc5d0 \uc0ac\uc6a9\ud560 \ub54c\ub3c4 \u201c\ub808\ucf54\ub4dc \ubc88\ud638\u201d\uc640 \u201c\ub05d\ub09c \ubb3c\ub9ac \uc904\u201d\uc744 \uad6c\ubd84\ud574\uc11c \uc801\ub294 \uac8c \uc815\ud655\ud574\uc694.[1]<\/p>\n<p>\ub204\ub77d\ub41c <code>memo<\/code>\ub294 <code>None<\/code>, \ub9c8\uc9c0\ub9c9 \ub808\ucf54\ub4dc\uc758 \uc874\uc7ac\ud558\ub294 \ube48 \ud544\ub4dc\ub294 <code>&#x27;&#x27;<\/code>\uc600\uc5b4\uc694. \uc608\uc81c\ub294 \uc55e\uc758 \uacbd\uc6b0\ub9cc \ub204\ub77d\uc73c\ub85c \ucc98\ub9ac\ud558\uace0 \ub4a4\uc758 \ube48 \uac12\uc740 \ud1b5\uacfc\uc2dc\ucf1c\uc694. \uc5c5\ubb34\uc5d0\uc11c \uba54\ubaa8\ub97c \ubc18\ub4dc\uc2dc \ucc44\uc6cc\uc57c \ud55c\ub2e4\uba74 \ube48 \ubb38\uc790\uc5f4 \uac80\uc0ac\ub3c4 \ucd94\uac00\ud574\uc57c \ud574\uc694. CSV \ubb38\ubc95\uc744 \uc77d\uc5c8\ub2e4\ub294 \uc0ac\uc2e4\uc774 \uc5c5\ubb34\uc0c1 \uc720\ud6a8\ud55c \ud589\uc774\ub77c\ub294 \ubcf4\uc99d\uc740 \uc544\ub2c8\uc5d0\uc694.<\/p>\n<p><a href=\"https:\/\/danlabs.kr\/?p=3073\">JSONL\uc5d0\uc11c \uc624\ub958 \uc904\uc744 \ucc3e\uace0 \ucc98\ub9ac\ub97c \uacc4\uc18d\ud558\ub294 \uc608\uc81c<\/a>\uc640 \ub9c8\ucc2c\uac00\uc9c0\ub85c \uac00\uc838\uc624\uae30 \uc791\uc5c5\uc5d0\ub294 \uc2e4\ud328 \uae30\ub85d\uc774 \ud544\uc694\ud574\uc694. \uc774 \ucf54\ub4dc\ub294 \ub204\ub77d\u00b7\ucd08\uacfc \ud589\uc744 \ucd9c\ub825\ud558\uace0 \ub2e4\uc74c \ud589\uc73c\ub85c \ub118\uc5b4\uac00\ub294 \uc791\uc740 \uc2e4\ud5d8\uc774\uc5d0\uc694. \uc6b4\uc601\uc6a9\uc73c\ub85c \uc62e\uae38 \ub54c\ub294 \uc218\ub7c9\uc758 \uc815\uc218 \ubcc0\ud658, \ud5c8\uc6a9 \uac12, \uc911\ubcf5 \ucc98\ub9ac\uae4c\uc9c0 \uc5c5\ubb34 \uaddc\uce59\uc5d0 \ub9de\ucdb0 \ub354\ud574\uc57c \ud574\uc694. \ud30c\uc11c\uac00 \uc77d\uc5b4 \ub0b8 \uad6c\uc870\uc640 \uc11c\ube44\uc2a4\uac00 \ubc1b\uc544\ub4e4\uc77c \ub370\uc774\ud130 \uc0ac\uc774\uc758 \uacbd\uacc4\ub97c \ucf54\ub4dc\ub85c \ub0a8\uae30\ub294 \uac83\uc774 \ud575\uc2ec\uc774\uc5d0\uc694.<\/p>\n<p><strong>\ucc38\uace0<\/strong><\/p>\n<ul>\n<li><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/docs.python.org\/3\/library\/csv.html\">Python \uacf5\uc2dd \ubb38\uc11c \u2014 csv (\uc870\ud68c \ub2f9\uc2dc3.15.2 \ubb38\uc11c, 2026-11-20 \uc870\ud68c)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python csv.DictReader\ub85c \ub530\uc634\ud45c \uc548 \uc27c\ud45c\u00b7\uc904\ubc14\uafc8\uc744 \uc77d\uace0, restkey\uc640 restval\ub85c \uc5f4 \ucd08\uacfc\u00b7\ub204\ub77d\uc744 \uad6c\ubd84\ud574\uc694. Python 3.14.7 \uc2e4\ud589 \ucd9c\ub825\uacfc \ubb3c\ub9ac \uc904 \ubc88\ud638\uc758 \ucc28\uc774\ub97c \uc124\uba85\ud574\uc694.<\/p>\n","protected":false},"author":1,"featured_media":3133,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-3137","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\/dev-20261120-feat.jpg",1280,720,false],"thumbnail":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat-150x150.jpg",150,150,true],"medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat-300x169.jpg",300,169,true],"medium_large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat-768x432.jpg",640,360,true],"large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat-1024x576.jpg",640,360,true],"1536x1536":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat.jpg",1280,720,false],"2048x2048":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat.jpg",1280,720,false],"morenews-large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat.jpg",825,464,false],"morenews-medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat.jpg",590,332,false],"danlabs-list-small":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat-366x190.jpg",366,190,true],"danlabs-list-retina":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-20261120-feat.jpg",1280,720,false]},"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":"7","_links":{"self":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3137","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=3137"}],"version-history":[{"count":1,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3137\/revisions"}],"predecessor-version":[{"id":3138,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3137\/revisions\/3138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/media\/3133"}],"wp:attachment":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}