用法:
ConfigParser.BOOLEAN_STATES默認情況下,使用
getboolean()時,配置解析器會考慮以下值True:'1','yes','true','on'和以下值False:'0','no','false','off'。您可以通過指定字符串的自定義字典及其布爾結果來覆蓋它。例如:>>> custom = configparser.ConfigParser() >>> custom['section1'] = {'funky': 'nope'} >>> custom['section1'].getboolean('funky') Traceback (most recent call last): ... ValueError: Not a boolean: nope >>> custom.BOOLEAN_STATES = {'sure': True, 'nope': False} >>> custom['section1'].getboolean('funky') False其他典型的布爾對包括
accept/reject或enabled/disabled。
相關用法
- Python configparser.ConfigParser.readfp用法及代碼示例
- Python configparser.ConfigParser.SECTCRE用法及代碼示例
- Python configparser.ConfigParser.read用法及代碼示例
- Python configparser.BasicInterpolation用法及代碼示例
- Python configparser.ExtendedInterpolation用法及代碼示例
- Python contextlib.AsyncContextDecorator用法及代碼示例
- Python contextlib.AsyncExitStack用法及代碼示例
- Python contextlib.ExitStack.pop_all用法及代碼示例
- Python contextlib.redirect_stdout用法及代碼示例
- Python contextlib.aclosing用法及代碼示例
- Python contextlib.ExitStack用法及代碼示例
- Python contextlib.contextmanager用法及代碼示例
- Python contextvars.ContextVar.reset用法及代碼示例
- Python contextlib.closing用法及代碼示例
- Python contextlib.nullcontext用法及代碼示例
- Python contextlib.ContextDecorator用法及代碼示例
- Python contextvars.Context.run用法及代碼示例
- Python contextlib.suppress用法及代碼示例
- Python collections.somenamedtuple._replace用法及代碼示例
- Python collections.somenamedtuple._asdict用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 configparser.ConfigParser.BOOLEAN_STATES。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
