configparser — 配置文件剖析器

源代码: Lib/configparser.py


本模块提供 ConfigParser class which implements a basic configuration language which provides a structure similar to what’s found in Microsoft Windows INI files. You can use this to write Python programs which can be customized by end users easily.

注意

This library does not interpret or write the value-type prefixes used in the Windows Registry extended version of INI syntax.

另请参阅

模块 tomllib

TOML is a well-specified format for application configuration files. It is specifically designed to be an improved version of INI.

模块 shlex

Support for creating Unix shell-like mini-languages which can also be used for application configuration files.

模块 json

The json module implements a subset of JavaScript syntax which is sometimes used for configuration, but does not support comments.

快速入门

Let’s take a very basic configuration file that looks like this:

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
[forge.example]
User = hg
[topsecret.server.example]
Port = 50022
ForwardX11 = no