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.ConfigParser: 2 newlines at end of file (EOF)
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: ConfigParser writes a superfluous final blank line
View: 32917
Assigned To: Nosy List: PythonEnthusiast, eric.smith, martin.panter
Priority: normal Keywords:

Created on 2021-10-03 01:02 by PythonEnthusiast, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg403069 - (view) Author: Boštjan Mejak (PythonEnthusiast) Date: 2021-10-03 01:02
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?
msg403071 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-10-03 01:33
Please provide code that we can run that shows the problem.
msg403072 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2021-10-03 01:50
Looks like the same as Issue 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.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89512
2021-10-03 01:50:44martin.pantersetstatus: open -> closed

superseder: ConfigParser writes a superfluous final blank line

nosy: + martin.panter
messages: + msg403072
resolution: duplicate
stage: resolved
2021-10-03 01:33:58eric.smithsetnosy: + eric.smith
messages: + msg403071
2021-10-03 01:02:54PythonEnthusiastcreate