Skip to content

configparser.ConfigParser: 2 newlines at end of file (EOF) #89512

Closed

Description

@PedanticHacker
BPO 45349
Nosy @ericvsmith, @vadmium, @PedanticHacker
Superseder
  • bpo-32917: ConfigParser writes a superfluous final blank line
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-10-03.01:50:44.954>
    created_at = <Date 2021-10-03.01:02:54.160>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.11', '3.7', 'library']
    title = 'configparser.ConfigParser: 2 newlines at end of file (EOF)'
    updated_at = <Date 2021-10-03.01:50:44.949>
    user = 'https://github.com/PedanticHacker'

    bugs.python.org fields:

    activity = <Date 2021-10-03.01:50:44.949>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-03.01:50:44.954>
    closer = 'martin.panter'
    components = ['Library (Lib)']
    creation = <Date 2021-10-03.01:02:54.160>
    creator = 'PythonEnthusiast'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45349
    keywords = []
    message_count = 3.0
    messages = ['403069', '403071', '403072']
    nosy_count = 3.0
    nosy_names = ['eric.smith', 'martin.panter', 'PythonEnthusiast']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '32917'
    type = 'behavior'
    url = 'https://bugs.python.org/issue45349'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. PedanticHacker commented on Oct 3, 2021

      PedanticHackermannequin
      MannequinAuthor

      In every Python version that I've tested, writing a config.ini file (utilizing configparser.ConfigParser), the result is such that the config.ini file has 2 newlines at the end of the file.

      The problem is that source code editors like Sublime Text, or IDEs like PyCharm, already insert a newline at the end of a file, but then configparser.ConfigParser
      (or maybe the Python's write() function?) insert its own as well.

      Is it possible to fix this behavior?

    2. added
      3.11only security fixes
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Oct 3, 2021
    3. ericvsmith commented on Oct 3, 2021

      @ericvsmith
      Member

      Please provide code that we can run that shows the problem.

    4. vadmium commented on Oct 3, 2021

      @vadmium
      Member

      Looks like the same as bpo-32917. I presume there are two newlines at the end of the file because there are two newlines following every config section.

      IMO this is a minor cosmetic annoyance, just like writing a key with an empty value gets you a trailing space after the equals sign at the end of the line. Not worth changing as a bug fix, and not worth a special option, but maybe okay to change if the code is simple and it doesn't harm compatibility.

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard 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