Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用ConfigParse编辑具有无名节的文件_Python_Configparser - Fatal编程技术网

Python 使用ConfigParse编辑具有无名节的文件

Python 使用ConfigParse编辑具有无名节的文件,python,configparser,Python,Configparser,我正在尝试编辑一个Splunk配置文件,其中包含一个没有名称的节 配置文件 # Application-level permissions [] access = read : [ * ], write : [ admin, power ] 代码 但是它看起来不是一个有效的名称,因为它启动了相同的异常 >>> import configparser >>> config = configparser.RawConfigParser() >>&g

我正在尝试编辑一个Splunk配置文件,其中包含一个没有名称的节

配置文件

# Application-level permissions

[]
access = read : [ * ], write : [ admin, power ]
代码

但是它看起来不是一个有效的名称,因为它启动了相同的异常

>>> import configparser
>>> config = configparser.RawConfigParser()
>>> config.read('sh-apps-pro/indexed_volume/metadata/default.meta')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    config.read('sh-apps/pro/indexed_volume/metadata/default.meta')
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/backports/configparser/
__init__.py", line 705, in read
    self._read(fp, filename)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/backports/configparser/
__init__.py", line 1101, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
MissingSectionHeaderError: File contains no section headers.
file: 'sh-apps-pro/indexed_volume/metadata/default.meta', line: 4
u'[]\n'
config = configparser.RawConfigParser(default_section='')