tomllib
configparser — 配置文件剖析器
configparser
Added in version 3.11.
源代码: Lib/tomllib
本模块提供的接口用于剖析 TOML (汤姆的明显最小语言 https://toml.io )。本模块不支持写入 TOML。
另请参阅
The Tomli-W package is a TOML writer that can be used in conjunction with this module, providing a write API familiar to users of the standard library marshal and pickle 模块。
marshal
pickle
The TOML Kit package is a style-preserving TOML library with both read and write capability. It is a recommended replacement for this module for editing already existing TOML files.
此模块定义了下列函数:
读取 TOML (汤姆的明显最小语言) 文件。第 1 自变量应该是可读的且是二进制文件对象。返回 dict 。把 TOML 类型转换到 Python 使用此 转换表 .
dict
parse_float will be called with the string of every TOML float to be decoded. By default, this is equivalent to float(num_str) . This can be used to use another datatype or parser for TOML floats (e.g. decimal.Decimal )。可调用不得返回 dict 或 list ,否则 ValueError 被引发。
float(num_str)
decimal.Decimal
list
ValueError
A TOMLDecodeError 会被引发,在无效 TOML (汤姆的明显最小语言) 文档。
TOMLDecodeError
加载 TOML 从 str 对象。返回 dict 。把 TOML 类型转换到 Python 使用此 转换表 。 parse_float 自变量拥有相同含义如在 load() .
str
load()
下列异常是可用的:
子类化的 ValueError .
剖析 TOML (汤姆的明显最小语言) 文件:
import tomllib with open("pyproject.toml", "rb") as f: data = tomllib.load(f)
Parsing a TOML string:
import tomllib toml_str = """ python-version = "3.11.0" python-implementation = "CPython" """ data = tomllib.loads(toml_str)
TOML
Python
float (configurable with parse_float )
datetime.datetime ( tzinfo attribute set to an instance of datetime.timezone )
tzinfo
datetime.timezone
datetime.datetime ( tzinfo 属性设置为 None )
None
netrc — netrc 文件处理
netrc
键入搜索术语或模块、类、函数名称。