GitHub 博客园 Nanakon

配置文件

settings.cfg

[english]
greeting = Hello

[french]
greeting = Bonjour

[files]
home = /usr/local
bin = %(home)s/bin

test.py

python3 test.py

import configparser
cfg = configparser.ConfigParser()
cfg.read('settings.cfg')

print(cfg)
#<configparser.ConfigParser object at 0x10144fe80>

print(cfg['french'])
#<Section: french>

print(cfg['french']['greeting'])
#Bonjour

print(cfg['files']['bin'])
#/usr/local/bin

 

posted on 2016-08-07 15:25  jzm17173  阅读(70)  评论(0编辑  收藏  举报

导航

轻音