Memoize2

Python で設定ファイルをパース


$ cat ./setting.cfg
    [name]
        owner    = Shin Nakamura
        sales    = John Dogg

    [hash]
        keyName        = id
        valueName    = name

$ cat cfgParser_test.py
    #! /usr/bin/env python
    # -*- coding: utf-8 -*-

    import configparser

    cfg = configparser.ConfigParser()
    cfg.read('setting.cfg')
    print(cfg['name']['owner'])
    print('key is ' + cfg['hash']['keyName'])
    print('value is ' + cfg['hash']['valueName'])

$ cfgParser_test.py
    Shin Nakamura
    key is id
    value is name

 

Last modified: 2016-12-19

Page Top

Index

Bw

Author: 中村 心 Shin Nakamura, Email: sn(at)i.basicwerk.com


© Shin Nakamura/BasicWerk 2008 - 2017