LoginSignup
0
1

More than 5 years have passed since last update.

設定ファイル読み込み

Last updated at Posted at 2018-03-02
sample.ini
[session]
HOST = sample
USER = sample
PASSWORD = sample
sample.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import ConfigParser

#read ini
inifile = ConfigParser.SafeConfigParser()
inifile.read('/etc/sample.ini')

def _getini(inifile, section, name):
        try:
           return inifile.get(section, name)
        except Exception as e:
           logger.error('could not read configuration:' + name)
           sys.exit(1)

HOST = _getini(inifile, 'session', 'HOST')
USER = _getini(inifile, 'session', 'USER')
PASSWORD = _getini(inifile, 'session', 'PASSWORD')
0
1
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
1