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: comments taken as values in ConfigParser
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: drugelis, rhettinger, slyphon
Priority: normal Keywords:

Created on 2002-08-08 10:11 by drugelis, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg11873 - (view) Author: Artūras Kriukovas (drugelis) Date: 2002-08-08 10:11
Let's say we have config file config.conf with contents:


[forms]
....
myParameter = myValue # my comment here :) 
# and my comment here
....

[other sections]
.......


We run python code:

    import sys, os
    from ConfigParser import *
    fileLocations = ['......./config.conf']
    parser = ConfigParser()
    parser.read(fileLocations)
    parser.sections()

and when we run:
    parser.get('forms', 'manoParameter')

we get:
    'myValue # my comment here :)'

The comment is also included as key value. The second
comment is left out as it should be.
The simpliest way to fix it probaby would be remove all
string after the first '#' char (that is to leave
string part to first '#' char).
msg11874 - (view) Author: Jonathan Simms (slyphon) Date: 2002-08-17 16:41
Logged In: YES 
user_id=404786

Hello, 

In the documentation for the ConfigParser module, it 
says

"Lines *beginning* with "#" or ";" are ignored and may 
be used to provide comments. "

After reviewing the source for ConfigParser.py, as far 
as I can tell, the parser does NOT support end-of-line 
comments in config files.

Hope this helps, 
Jonathan
msg11875 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-18 20:44
Logged In: YES 
user_id=80475

Agreed, ConfigParser does match its documented 
behavior.  Exhancing the behavior to include mid-line 
comments would be problematic because some existing 
config files may already be using unescaped ; or # 
characters in the value field.

Marking bug as invalid and closing.
History
Date User Action Args
2022-04-10 16:05:34adminsetgithub: 37002
2002-08-08 10:11:19drugeliscreate