用法:
ConfigParser.SECTCRE
用於解析節標題的編譯正則表達式。默認匹配
[section]
到名稱"section"
。空格被認為是部分名稱的一部分,因此[ larch ]
將被讀取為名稱" larch "
的部分。如果不合適,請覆蓋此屬性。例如:>>> import re >>> config = """ ... [Section 1] ... option = value ... ... [ Section 2 ] ... another = val ... """ >>> typical = configparser.ConfigParser() >>> typical.read_string(config) >>> typical.sections() ['Section 1', ' Section 2 '] >>> custom = configparser.ConfigParser() >>> custom.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]") >>> custom.read_string(config) >>> custom.sections() ['Section 1', 'Section 2']
注意
雖然 ConfigParser 對象也使用
OPTCRE
屬性來識別選項行,但不建議覆蓋它,因為這會幹擾構造函數選項allow_no_value
和delimiters
。
相關用法
- Python configparser.ConfigParser.readfp用法及代碼示例
- Python configparser.ConfigParser.BOOLEAN_STATES用法及代碼示例
- 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.SECTCRE。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。