{"id":79,"date":"2025-11-03T03:56:23","date_gmt":"2025-11-03T03:56:23","guid":{"rendered":"https:\/\/5047878.net\/blog\/?p=79"},"modified":"2025-11-03T03:56:24","modified_gmt":"2025-11-03T03:56:24","slug":"%ed%8c%8c%ec%9d%b4%ec%8d%ac%ec%9c%bc%eb%a1%9c-ini-%ec%84%a4%ec%a0%95-%ed%8c%8c%ec%9d%bc-%ec%9d%bd%ea%b3%a0-%ec%93%b0%ea%b8%b0-%ec%99%84%eb%b2%bd-%ea%b0%80%ec%9d%b4%eb%93%9c","status":"publish","type":"post","link":"https:\/\/5047878.net\/?p=79","title":{"rendered":"\ud30c\uc774\uc36c\uc73c\ub85c ini \uc124\uc815 \ud30c\uc77c \uc77d\uace0 \uc4f0\uae30 \uc644\ubcbd \uac00\uc774\ub4dc"},"content":{"rendered":"<h2>\ud83d\udca1 \ud30c\uc774\uc36c\uc73c\ub85c ini \uc124\uc815 \ud30c\uc77c \uc77d\uace0 \uc4f0\uae30 \uc644\ubcbd \uac00\uc774\ub4dc<\/h2>\n<p>\n\ud504\ub85c\uadf8\ub7a8\uc744 \uac1c\ubc1c\ud558\ub2e4 \ubcf4\uba74 \ud658\uacbd\uc124\uc815 \ud30c\uc77c\uc744 \ub530\ub85c \uad00\ub9ac\ud574\uc57c \ud560 \ub54c\uac00 \ub9ce\uc2b5\ub2c8\ub2e4.<br \/>\n\uc608\ub97c \ub4e4\uc5b4 \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc811\uc18d \uc815\ubcf4, \ubc84\uc804 \uc815\ubcf4, \uc2e4\ud589 \uc635\uc158 \ub4f1\uc744 \ucf54\ub4dc\uc640 \ubd84\ub9ac\ud574 \uad00\ub9ac\ud558\uba74 \uc720\uc9c0\ubcf4\uc218\uac00 \ud6e8\uc52c \uc26c\uc6cc\uc9d1\ub2c8\ub2e4.<br \/>\n\uc774\ub7f4 \ub54c \uac00\uc7a5 \uac04\ub2e8\ud558\uace0 \uac00\ub3c5\uc131 \uc88b\uc740 \ud615\uc2dd\uc774 \ubc14\ub85c <strong>INI \ud30c\uc77c<\/strong>\uc785\ub2c8\ub2e4.\n<\/p>\n<p>\n\ud30c\uc774\uc36c\uc5d0\uc11c\ub294 \ud45c\uc900 \ub77c\uc774\ube0c\ub7ec\ub9ac\uc778 <code>configparser<\/code> \ubaa8\ub4c8\uc744 \uc774\uc6a9\ud574 ini \ud30c\uc77c\uc744 \uc190\uc27d\uac8c \uc77d\uace0 \uc4f8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br \/>\n\uc774\ubc88 \uae00\uc5d0\uc11c\ub294 <strong>ini \ud30c\uc77c \uc0dd\uc131 \u2192 \uc77d\uae30 \u2192 \uc218\uc815 \u2192 \uc800\uc7a5<\/strong> \uacfc\uc815\uc744 \ud558\ub098\uc758 \uc608\uc81c\ub85c \uc790\uc138\ud788 \uc0b4\ud3b4\ubcf4\uaca0\uc2b5\ub2c8\ub2e4.\n<\/p>\n<hr>\n<h3>\ud83d\udcc1 1\ufe0f\u20e3 INI \ud30c\uc77c \uae30\ubcf8 \uad6c\uc870<\/h3>\n<p>\uc6b0\uc120 ini \ud30c\uc77c\uc740 <strong>\uc139\uc158(section)<\/strong>\uacfc <strong>\ud0a4-\uac12 \uc30d<\/strong>\uc73c\ub85c \uad6c\uc131\ub429\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4 \uc544\ub798\uc640 \uac19\uc740 \uc124\uc815 \ud30c\uc77c\uc774 \uc788\ub2e4\uace0 \ud574\ubd05\uc2dc\ub2e4.<\/p>\n<pre><code>[database]\nhost = localhost\nuser = root\npassword = 1234\nport = 3306\n\n[app]\ndebug = True\nversion = 1.0.0\n<\/code><\/pre>\n<p>\n\uac01 <code>[]<\/code>\ub85c \ub458\ub7ec\uc2f8\uc778 \ubd80\ubd84\uc740 \uc139\uc158 \uc774\ub984\uc774\uace0, \ub0b4\ubd80\uc5d0 key=value \ud615\ud0dc\ub85c \uac12\uc774 \uc800\uc7a5\ub429\ub2c8\ub2e4.<br \/>\n\uc774\uc81c \ud30c\uc774\uc36c \ucf54\ub4dc\ub85c \uc774 \ud30c\uc77c\uc744 \uc77d\uc5b4\ubcfc\uae4c\uc694?\n<\/p>\n<hr>\n<h3>\ud83e\udde0 2\ufe0f\u20e3 INI \ud30c\uc77c \uc77d\uae30 (Read)<\/h3>\n<pre><code class=\"language-python\">\nimport configparser\n\nconfig = configparser.ConfigParser()\nconfig.read('config.ini', encoding='utf-8')\n\nhost = config['database']['host']\nuser = config['database']['user']\nport = config.getint('database', 'port')\ndebug = config.getboolean('app', 'debug')\n\nprint(f\"DB: {host}, USER: {user}, PORT: {port}, DEBUG: {debug}\")\n<\/code><\/pre>\n<p>\n<code>configparser.ConfigParser()<\/code> \uac1d\uccb4\ub97c \uc774\uc6a9\ud574 ini \ud30c\uc77c\uc744 \ubd88\ub7ec\uc624\uace0,<br \/>\n\uc139\uc158 \uc774\ub984\uacfc \ud0a4 \uc774\ub984\uc73c\ub85c \uc6d0\ud558\ub294 \uac12\uc744 \uac00\uc838\uc62c \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br \/>\n\ub610\ud55c \uc22b\uc790\ub098 \ubd88\ub9ac\uc5b8 \uac12\uc740 <code>getint()<\/code>, <code>getboolean()<\/code>\uc73c\ub85c \ubcc0\ud658\ud558\uc5ec \uc77d\uc744 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n<\/p>\n<hr>\n<h3>\ud83e\uddf1 3\ufe0f\u20e3 INI \ud30c\uc77c \uc0dd\uc131 \ubc0f \uc4f0\uae30 (Write)<\/h3>\n<pre><code class=\"language-python\">\nimport configparser\n\nconfig = configparser.ConfigParser()\n\nconfig['database'] = {\n    'host': '127.0.0.1',\n    'user': 'admin',\n    'password': 'abcd',\n    'port': '3306'\n}\n\nconfig['app'] = {\n    'debug': 'False',\n    'version': '1.0.0'\n}\n\nwith open('config.ini', 'w', encoding='utf-8') as f:\n    config.write(f)\n\nprint(\"config.ini \ud30c\uc77c\uc774 \uc0dd\uc131\ub418\uc5c8\uc2b5\ub2c8\ub2e4.\")\n<\/code><\/pre>\n<p>\n\uc704 \ucf54\ub4dc\ub97c \uc2e4\ud589\ud558\uba74 <strong>config.ini<\/strong> \ud30c\uc77c\uc774 \uc790\ub3d9\uc73c\ub85c \uc0dd\uc131\ub418\uba70,<br \/>\n\uc9c0\uc815\ud55c \uc139\uc158\uacfc \ud0a4-\uac12\uc774 \uc800\uc7a5\ub429\ub2c8\ub2e4.\n<\/p>\n<hr>\n<h3>\ud83d\udd27 4\ufe0f\u20e3 INI \ud30c\uc77c \uc218\uc815 \ubc0f \uc5c5\ub370\uc774\ud2b8 (Update)<\/h3>\n<pre><code class=\"language-python\">\nimport configparser\n\nconfig = configparser.ConfigParser()\nconfig.read('config.ini', encoding='utf-8')\n\nconfig['database']['password'] = 'new_password'\nconfig['app']['debug'] = 'True'\n\n# \uc0c8 \uc139\uc158 \ucd94\uac00\nif not config.has_section('user'):\n    config.add_section('user')\nconfig.set('user', 'name', 'HCCHOI')\n\nwith open('config.ini', 'w', encoding='utf-8') as f:\n    config.write(f)\n\nprint(\"\uc124\uc815\uc774 \uc218\uc815\ub418\uc5c8\uc2b5\ub2c8\ub2e4.\")\n<\/code><\/pre>\n<p>\n\uc774\ucc98\ub7fc \uae30\uc874 \uac12\uc740 \ubc14\ub85c \uc218\uc815\ud560 \uc218 \uc788\uace0,<br \/>\n\uc0c8\ub85c\uc6b4 \uc139\uc158\uc744 <code>add_section()<\/code>\uc73c\ub85c \ucd94\uac00\ud560 \uc218\ub3c4 \uc788\uc2b5\ub2c8\ub2e4.\n<\/p>\n<hr>\n<h3>\ud83d\ude80 5\ufe0f\u20e3 \uc804\uccb4 \uc608\uc81c \ucf54\ub4dc (\uc77d\uae30 + \uc4f0\uae30 + \uc218\uc815)<\/h3>\n<p>\uc544\ub798 \uc608\uc81c\ub294 ini \ud30c\uc77c\uc744 \uc0dd\uc131, \uc77d\uae30, \uc218\uc815\uae4c\uc9c0 \ud55c \ubc88\uc5d0 \uc2e4\ud589\ud558\ub294 \uc644\uc804\ud55c \ucf54\ub4dc\uc785\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-python\">\nimport configparser\nimport os\n\nCONFIG_FILE = 'config.ini'\n\ndef create_default_config():\n    config = configparser.ConfigParser()\n    config['database'] = {'host':'localhost','user':'root','password':'1234','port':'3306'}\n    config['app'] = {'debug':'True','version':'1.0.0'}\n    with open(CONFIG_FILE, 'w', encoding='utf-8') as f:\n        config.write(f)\n\ndef read_config():\n    config = configparser.ConfigParser()\n    config.read(CONFIG_FILE, encoding='utf-8')\n    print(\"[database]\", dict(config['database']))\n    print(\"[app]\", dict(config['app']))\n\ndef update_config():\n    config = configparser.ConfigParser()\n    config.read(CONFIG_FILE, encoding='utf-8')\n    config['database']['password'] = 'new_password'\n    config['app']['debug'] = 'False'\n    if not config.has_section('user'):\n        config.add_section('user')\n    config['user']['name'] = 'HCCHOI'\n    with open(CONFIG_FILE, 'w', encoding='utf-8') as f:\n        config.write(f)\n\nif __name__ == '__main__':\n    if not os.path.exists(CONFIG_FILE):\n        create_default_config()\n    read_config()\n    update_config()\n    read_config()\n<\/code><\/pre>\n<hr>\n<h3>\ud83e\udde9 6\ufe0f\u20e3 \uc2e4\ud589 \uacb0\uacfc<\/h3>\n<pre><code>\n[+] \uae30\ubcf8 config.ini \ud30c\uc77c\uc774 \uc0dd\uc131\ub418\uc5c8\uc2b5\ub2c8\ub2e4.\n\n[database] {'host': 'localhost', 'user': 'root', 'password': '1234', 'port': '3306'}\n[app] {'debug': 'True', 'version': '1.0.0'}\n\n\uc124\uc815\uc774 \uc218\uc815\ub418\uc5c8\uc2b5\ub2c8\ub2e4.\n\n[database] {'host': 'localhost', 'user': 'root', 'password': 'new_password', 'port': '3306'}\n[app] {'debug': 'False', 'version': '1.0.0'}\n[user] {'name': 'HCCHOI'}\n<\/code><\/pre>\n<hr>\n<h3>\u2705 \ub9c8\ubb34\ub9ac<\/h3>\n<p>\n<code>configparser<\/code>\ub294 \ubcc4\ub3c4 \ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58\uac00 \ud544\uc694 \uc5c6\uc73c\uba70,<br \/>\n\uac00\ubccd\uace0 \uc9c1\uad00\uc801\uc778 \ubc29\uc2dd\uc73c\ub85c \uc124\uc815\uac12\uc744 \uad00\ub9ac\ud560 \uc218 \uc788\ub294 \uac15\ub825\ud55c \ub3c4\uad6c\uc785\ub2c8\ub2e4.<br \/>\n\ud2b9\ud788 \ud30c\uc774\uc36c \ud504\ub85c\uadf8\ub7a8\uc758 \ud658\uacbd\uc124\uc815, \uc11c\ubc84 \uc124\uc815, \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc5f0\uacb0\uc815\ubcf4 \uad00\ub9ac \ub4f1\uc5d0 \ub9ce\uc774 \ud65c\uc6a9\ub429\ub2c8\ub2e4.\n<\/p>\n<p>\n\ud658\uacbd\uc124\uc815\uc744 \ucf54\ub4dc\uc5d0\uc11c \ubd84\ub9ac\ud558\uba74 \ud504\ub85c\uadf8\ub7a8\uc758 \uc720\uc9c0\ubcf4\uc218\uc131\uacfc \uc7ac\uc0ac\uc6a9\uc131\uc774 \ud06c\uac8c \ud5a5\uc0c1\ub429\ub2c8\ub2e4.<br \/>\n\uc9c0\uae08 \ubc14\ub85c <strong>configparser<\/strong>\ub97c \ud65c\uc6a9\ud574\ubcf4\uc138\uc694!\n<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udca1 \ud30c\uc774\uc36c\uc73c\ub85c ini \uc124\uc815 \ud30c\uc77c \uc77d\uace0 \uc4f0\uae30 \uc644\ubcbd \uac00\uc774\ub4dc \ud504\ub85c\uadf8\ub7a8\uc744 \uac1c\ubc1c\ud558\ub2e4 \ubcf4\uba74 \ud658\uacbd\uc124\uc815 \ud30c\uc77c\uc744 \ub530\ub85c \uad00\ub9ac\ud574\uc57c \ud560 \ub54c\uac00<\/p>\n","protected":false},"author":1,"featured_media":50,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,7],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-python"],"_links":{"self":[{"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/5047878.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":1,"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions\/80"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/5047878.net\/index.php?rest_route=\/wp\/v2\/media\/50"}],"wp:attachment":[{"href":"https:\/\/5047878.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/5047878.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/5047878.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}