zoukankan      html  css  js  c++  java
  • Python configparser 读取指定节点内容失败

    # !/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
  • 相关阅读:
    Python解释器相关知识
    简单了解下Flask
    Scoket编程
    __file__的作用
    jquery编写可折叠列表
    浑浑噩噩的一天
    js实现杨辉三角
    js闭包
    python读取word表格
    HTMLTestRunner报告
  • 原文地址:https://www.cnblogs.com/cheese320/p/9061125.html
Copyright © 2011-2022 走看看