Tag:Python configparser
Article From:https://www.cnblogs.com/cheese320/p/9061118.html

ymal : It’s a config file

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

import configparser

# Generate a config file, which generates a example.ini file under the current directory.
config = configparser.ConfigParser()

config["default"] = {"ServerAliveInterval": "45",

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:

# Read the config file
conf = configparser.ConfigParser()

print(conf.sections())  # Print out the contents of the file, that is, [[default]], but the default is not printed.
print(conf.default_section)  # Print the default node, that is, [default]
print(conf['bitbucket.org']['user'])  # Read the contents of the specified node. Why read failed? TODO


Link of this Article: Python ymal modules and configparser

Leave a Reply

Your email address will not be published. Required fields are marked *