美文网首页
Python加载配置文件

Python加载配置文件

作者: 袁先生的笔记 | 来源:发表于2021-03-09 21:46 被阅读0次
  • 代码
import ConfigParser  # python2
import configparser  # python3

try:
    cf = ConfigParser.ConfigParser()  # python2
    cf = configparser.ConfigParser()  # python3
    cf.read('conf.ini')
    workplace = cf.get('product', 'workplace')
except Exception:
    pass
  • 配置文件conf.ini
[product]
workplace = /data/app/product

[test]
workplace = /data/app/test

相关文章

网友评论

      本文标题:Python加载配置文件

      本文链接:https://www.haomeiwen.com/subject/fnzbqltx.html