Content-Length: 276116 | pFad | https://github.com/python/cpython/issues/129678

ad ConfigParser: writing a config with an empty unnamed section adds an extra newline to the beginning of the file · Issue #129678 · python/cpython · GitHub
Skip to content

ConfigParser: writing a config with an empty unnamed section adds an extra newline to the beginning of the file #129678

Description

@PalmtopTiger

Bug report

Bug description:

If you read a config with an empty unnamed section using ConfigParser with allow_unnamed_section set to True and write it back, the resulting file will contain an extra newline at the beginning:

from configparser import ConfigParser
from io import StringIO
cfg = ConfigParser(allow_unnamed_section=True)
cfg.read_string('[sect]')
output = StringIO()
cfg.write(output)
print(repr(output.getvalue())) # '\n[sect]\n\n'

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/129678

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy