# !/user/bin/python
# -*- coding: utf-8 -*-

import configparser

# 生成一个config文件
config = configparser.ConfigParser()

config["default"] = {"ServerAliveInterval": "45",
                     "Compression":"45",
                     "CompressionLevel":"9"}

config["bitbucket.org"] = {}
config["bitbucket.org"]["user"] = "hg"
config["topsecret.server.com"] = {}
topsecret = config["topsecret.server.com"]
topsecret["host port"] = "5002"
topsecret["portwardxii"] = "no"

with open("example.ini","w") as configfile:
    config.write(configfile)


# 读取config 文件
conf = configparser.ConfigParser()
conf.read("example.xml")

print(conf.sections())  # 打印出文件的节点, 即[ ]里的内容, 但是[default]默认是不打印的
print(conf.default_section)  # 打印默认节点, 即[default]
print(conf['bitbucket.org']['user'])  # 读取指定节点的内容. 为什么读取失败? TODO

 

相关文章:

  • 2021-05-31
  • 2021-09-24
  • 2022-12-23
  • 2022-03-03
  • 2022-01-06
  • 2022-12-23
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-12-08
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
相关资源
相似解决方案