• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
增强的一亩三分地
增强的一亩三分地
博客园          联系   管理     
python 配置文件操作
引入库
import configparser
配置文件读取

样例配置文件

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
  
[bitbucket.org]
User = Atlan
  
[topsecret.server.com]
Port = 50022
ForwardX11 = no
config = configparser.ConfigParser()
config.read('example.ini')
print(config['bitbucket.org']['user'])

config相当于是一个字典,读出的所有值均为字符串,如果有需要,手动转换即可

posted on 2019-11-03 20:42  -leanard-  阅读(6)  评论(0)    收藏  举报  来源
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3