0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

学習記録>pythonプログラムでの設定ファイルの読み込み方法

Posted at

概要

以下を学習記録として小ネタを記載しました。
随時更新していきます。
1)pythonプログラムでの設定ファイルの読み込み方法
  >configparserの使用

1)pythonプログラムでの設定ファイルの読み込み方法

今回はconfigparserを使用します。

実行方法.
python3 test.py
config.ini
[DEFAULT]
;変数=値の形式で記載していく
num1 = 1
num2 = 2
num3 = 3
num4 = 4

test.py
# coding: utf-8
# configparserは標準モジュール
import configparser


# configparserの宣言とiniファイルの読み込み
config_ini = configparser.ConfigParser()
config_ini.read('config.ini', encoding='utf-8')

num1 = config_ini['DEFAULT']['num1']
num2 = config_ini['DEFAULT']['num2']
num3 = config_ini['DEFAULT']['num3']
num4 = config_ini['DEFAULT']['num4']
print(num1)
print(num2)
print(num3)
print(num4)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?