This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Configparser is not reading Indended Sections as Mentioned in Docs
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, Vignesh Rajendran, python-dev
Priority: normal Keywords:

Created on 2020-07-24 06:01 by Vignesh Rajendran, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27830 open python-dev, 2021-08-19 11:41
Messages (2)
msg374160 - (view) Author: Vignesh Rajendran (Vignesh Rajendran) Date: 2020-07-24 06:01
https://github.com/jaraco/configparser/issues/55

Please check the Bug is raised also in Github,

Sections can be intended is specified in the documentation.

When I read the indented section, its throwing section not found an error in python 3.8

as per Documentation https://docs.python.org/3/library/configparser.html
[You can use comments]
like this
; or this

    [Sections Can Be Indented]
    can_values_be_as_well = True
    does_that_mean_anything_special = False
    purpose = formatting for readability
but this is not working.
check this https://stackoverflow.com/questions/62833787/how-to-read-indentated-sections-with-python-configparser/62836972?noredirect=1#comment111176192_62836972

if i read an indented section, its showing section not found.

my file:
[section]
a = 0.3

    [subsection]
    b = 123
import configparser
conf = configparser.ConfigParser()
conf.read("./test.conf")
a = conf['section']['a']
print(a)

Output of a:

0.3

[subsection]
b = 123

Expected a : 0.3 only

But Section b is not found
msg374162 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2020-07-24 07:03
In your example you're instantiating ConfigParser with default parameters, meaning empty_lines_in_values equals True, which leads to key "a" consuming everything on the following indented lines. If you're were to specify False as the value for empty_lines_in_values, you'd see the desired behaviour.

The examples in documentation work just fine, as long as you copy them exactly. The reason they do is that there isn't a final value in the non-indented section, but only comments. In any case empty_lines_in_values is what you should be using.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85551
2021-08-19 11:41:53python-devsetnosy: + python-dev

pull_requests: + pull_request26294
2020-07-24 07:03:35SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg374162

resolution: not a bug
stage: resolved
2020-07-24 06:03:46Vignesh Rajendransetcomponents: + Library (Lib)
2020-07-24 06:01:23Vignesh Rajendrancreate