<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ko">
	<id>https://devcafe.co.kr/w/index.php?action=history&amp;feed=atom&amp;title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser</id>
	<title>파이썬 config parser - 편집 역사</title>
	<link rel="self" type="application/atom+xml" href="https://devcafe.co.kr/w/index.php?action=history&amp;feed=atom&amp;title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser"/>
	<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser&amp;action=history"/>
	<updated>2026-04-04T05:46:10Z</updated>
	<subtitle>이 문서의 편집 역사</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://devcafe.co.kr/w/index.php?title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser&amp;diff=1416&amp;oldid=prev</id>
		<title>2025년 5월 19일 (월) 23:31에 Devcafe님의 편집</title>
		<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser&amp;diff=1416&amp;oldid=prev"/>
		<updated>2025-05-19T23:31:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ko&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 이전 판&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2025년 5월 20일 (화) 08:31 판&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l103&quot;&gt;103번째 줄:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;103번째 줄:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# config_file_read.py&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# config_file_read.py&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;source lang=sql&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from configparser import ConfigParser, ExtendedInterpolation&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from configparser import ConfigParser, ExtendedInterpolation&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l110&quot;&gt;110번째 줄:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;111번째 줄:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;print(parser.get(&amp;#039;files&amp;#039;, &amp;#039;python_path&amp;#039;))   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;print(parser.get(&amp;#039;files&amp;#039;, &amp;#039;python_path&amp;#039;))   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# /usr/local/bin/python3&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# /usr/local/bin/python3&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/source&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;여기서 ExtendedInterpolation 을 추가로 import해준다&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;여기서 ExtendedInterpolation 을 추가로 import해준다&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Devcafe</name></author>
	</entry>
	<entry>
		<id>https://devcafe.co.kr/w/index.php?title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser&amp;diff=54&amp;oldid=prev</id>
		<title>Devcafe: 새 문서: == 파이썬, ini파일 파서(Config Parser) ==  Python Config Parser Config Parser Config Parserkishstats.com  == Create Config File == &lt;source lang=python&gt; # config_file_create.py from configparser import ConfigParser config = ConfigParser() config[&#039;settings&#039;] = {     &#039;debug&#039;: &#039;true&#039;,     &#039;secret_key&#039;: &#039;abc123&#039;,     &#039;log_path&#039;: &#039;/my_app/log&#039; }  config[&#039;db&#039;] = {     &#039;db_name&#039;: &#039;myapp_dev&#039;,     &#039;db_host&#039;: &#039;localhost&#039;,     &#039;db_port&#039;: &#039;8889&#039; }  config[&#039;files&#039;] = {     &#039;use_cdn&#039;:...</title>
		<link rel="alternate" type="text/html" href="https://devcafe.co.kr/w/index.php?title=%ED%8C%8C%EC%9D%B4%EC%8D%AC_config_parser&amp;diff=54&amp;oldid=prev"/>
		<updated>2024-10-04T15:37:07Z</updated>

		<summary type="html">&lt;p&gt;새 문서: == 파이썬, ini파일 파서(Config Parser) ==  Python Config Parser Config Parser Config Parserkishstats.com  == Create Config File == &amp;lt;source lang=python&amp;gt; # config_file_create.py from configparser import ConfigParser config = ConfigParser() config[&amp;#039;settings&amp;#039;] = {     &amp;#039;debug&amp;#039;: &amp;#039;true&amp;#039;,     &amp;#039;secret_key&amp;#039;: &amp;#039;abc123&amp;#039;,     &amp;#039;log_path&amp;#039;: &amp;#039;/my_app/log&amp;#039; }  config[&amp;#039;db&amp;#039;] = {     &amp;#039;db_name&amp;#039;: &amp;#039;myapp_dev&amp;#039;,     &amp;#039;db_host&amp;#039;: &amp;#039;localhost&amp;#039;,     &amp;#039;db_port&amp;#039;: &amp;#039;8889&amp;#039; }  config[&amp;#039;files&amp;#039;] = {     &amp;#039;use_cdn&amp;#039;:...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;새 문서&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 파이썬, ini파일 파서(Config Parser) ==&lt;br /&gt;
&lt;br /&gt;
Python Config Parser&lt;br /&gt;
Config Parser&lt;br /&gt;
Config Parserkishstats.com&lt;br /&gt;
&lt;br /&gt;
== Create Config File ==&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
# config_file_create.py&lt;br /&gt;
from configparser import ConfigParser&lt;br /&gt;
config = ConfigParser()&lt;br /&gt;
config[&amp;#039;settings&amp;#039;] = {&lt;br /&gt;
    &amp;#039;debug&amp;#039;: &amp;#039;true&amp;#039;,&lt;br /&gt;
    &amp;#039;secret_key&amp;#039;: &amp;#039;abc123&amp;#039;,&lt;br /&gt;
    &amp;#039;log_path&amp;#039;: &amp;#039;/my_app/log&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
config[&amp;#039;db&amp;#039;] = {&lt;br /&gt;
    &amp;#039;db_name&amp;#039;: &amp;#039;myapp_dev&amp;#039;,&lt;br /&gt;
    &amp;#039;db_host&amp;#039;: &amp;#039;localhost&amp;#039;,&lt;br /&gt;
    &amp;#039;db_port&amp;#039;: &amp;#039;8889&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
config[&amp;#039;files&amp;#039;] = {&lt;br /&gt;
    &amp;#039;use_cdn&amp;#039;: &amp;#039;false&amp;#039;,&lt;br /&gt;
    &amp;#039;images_path&amp;#039;: &amp;#039;/my_app/images&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
with open(&amp;#039;./dev.ini&amp;#039;, &amp;#039;w&amp;#039;) as f:&lt;br /&gt;
      config.write(f)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
위의 코드를 실행하면 dev.ini 파일이 워킹 디렉토리에 만들어진다.&lt;br /&gt;
&lt;br /&gt;
== ini 파일 확인 ==&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
# dev.ini&lt;br /&gt;
[settings]&lt;br /&gt;
debug = true&lt;br /&gt;
secret_key = abc123&lt;br /&gt;
log_path = /my_app/log&lt;br /&gt;
&lt;br /&gt;
[db]&lt;br /&gt;
db_name = myapp_dev&lt;br /&gt;
db_host = localhost&lt;br /&gt;
db_port = 8889&lt;br /&gt;
&lt;br /&gt;
[files]&lt;br /&gt;
use_cdn = false&lt;br /&gt;
images_path = /my_app/images&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Read Config File ==&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
# config_file_read.py&lt;br /&gt;
from configparser import ConfigParser&lt;br /&gt;
&lt;br /&gt;
parser = ConfigParser()&lt;br /&gt;
parser.read(&amp;#039;dev.ini&amp;#039;)&lt;br /&gt;
print(parser.sections())  # [&amp;#039;settings&amp;#039;, &amp;#039;db&amp;#039;, &amp;#039;files&amp;#039;]&lt;br /&gt;
print(parser.get(&amp;#039;settings&amp;#039;, &amp;#039;secret_key&amp;#039;))  # abc123&lt;br /&gt;
print(parser.options(&amp;#039;settings&amp;#039;))  # [&amp;#039;debug&amp;#039;, &amp;#039;secret_key&amp;#039;, &amp;#039;log_path&amp;#039;]&lt;br /&gt;
print(&amp;#039;db&amp;#039; in parser)  # True&lt;br /&gt;
print(parser.get(&amp;#039;db&amp;#039;, &amp;#039;db_port&amp;#039;), type(parser.get(&amp;#039;db&amp;#039;, &amp;#039;db_port&amp;#039;)))  # 8889 &amp;lt;class &amp;#039;str&amp;#039;&amp;gt;&lt;br /&gt;
print(int(parser.get(&amp;#039;db&amp;#039;, &amp;#039;db_port&amp;#039;)))  # 8889 (as int)&lt;br /&gt;
print(parser.getint(&amp;#039;db&amp;#039;, &amp;#039;db_default_port&amp;#039;, fallback=3306))  # 3306&lt;br /&gt;
print(parser.getboolean(&amp;#039;settings&amp;#039;, &amp;#039;debug&amp;#039;, fallback=False))  # True&lt;br /&gt;
sections(): 모든 section 리스트 반환&lt;br /&gt;
get(&amp;lt;section_name&amp;gt;,&amp;lt;option_name&amp;gt;): 섹션의 옵션값 str로 반환&lt;br /&gt;
getint(),getfloat(),getboolean(): int/float/boolean으로 반환&lt;br /&gt;
options(&amp;lt;section_name&amp;gt;):섹션 안의 선택가능한 옵션들반환&lt;br /&gt;
in: 섹션 존재 여부 확인&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using String Interpolation ==&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
# config_file_create.py&lt;br /&gt;
from configparser import ConfigParser&lt;br /&gt;
# ...&lt;br /&gt;
&lt;br /&gt;
config[&amp;#039;settings&amp;#039;] = {&lt;br /&gt;
    &amp;#039;debug&amp;#039;: &amp;#039;true&amp;#039;,&lt;br /&gt;
    &amp;#039;secret_key&amp;#039;: &amp;#039;abc123&amp;#039;,&lt;br /&gt;
    &amp;#039;log_path&amp;#039;: &amp;#039;/my_app/log&amp;#039;,&lt;br /&gt;
    &amp;#039;python_version&amp;#039;: &amp;#039;3&amp;#039;,&lt;br /&gt;
    &amp;#039;packages_path&amp;#039;: &amp;#039;/usr/local&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# ...&lt;br /&gt;
&lt;br /&gt;
config[&amp;#039;files&amp;#039;] = {&lt;br /&gt;
    &amp;#039;use_cdn&amp;#039;: &amp;#039;false&amp;#039;,&lt;br /&gt;
    &amp;#039;images_path&amp;#039;: &amp;#039;/my_app/images&amp;#039;,&lt;br /&gt;
    &amp;#039;python_path&amp;#039;: &amp;#039;${settings:packages_path}/bin/python${settings:python_version}&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# ...&lt;br /&gt;
config[&amp;#039;settings&amp;#039;]에 python_version&amp;amp;packages_path를 추가&lt;br /&gt;
&lt;br /&gt;
config[&amp;#039;files&amp;#039;] 에 python_path를 추가&lt;br /&gt;
&lt;br /&gt;
여기서 표시 형식은 ${&amp;lt;section name&amp;gt;:&amp;lt;option name&amp;gt;} 형태로 기입&lt;br /&gt;
&lt;br /&gt;
# config_file_read.py&lt;br /&gt;
from configparser import ConfigParser, ExtendedInterpolation&lt;br /&gt;
&lt;br /&gt;
parser = ConfigParser(interpolation=ExtendedInterpolation())&lt;br /&gt;
parser.read(&amp;#039;dev.ini&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
print(parser.get(&amp;#039;files&amp;#039;, &amp;#039;python_path&amp;#039;))  &lt;br /&gt;
# /usr/local/bin/python3&lt;br /&gt;
&lt;br /&gt;
여기서 ExtendedInterpolation 을 추가로 import해준다&lt;br /&gt;
&lt;br /&gt;
ConfigParser(interpolation=ExtendedInterpolation()) 변경&lt;br /&gt;
&lt;br /&gt;
[[category:python]]&lt;/div&gt;</summary>
		<author><name>Devcafe</name></author>
	</entry>
</feed>