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: Passing a semicolon as a value
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Daniel.Gordon, berker.peksag, lukasz.langa, michaelgruenewald
Priority: normal Keywords:

Created on 2012-10-31 15:01 by Daniel.Gordon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
reproducer.py berker.peksag, 2012-10-31 23:47
Messages (4)
msg174288 - (view) Author: Daniel Gordon (Daniel.Gordon) Date: 2012-10-31 15:01
I have a configuration file containing a key and value:
delimiter=;

Using ConfigParser,
the resulting value of the key delimiter is empty.
Expected behavior should be a semicolon as the value.

This behavior occurred on Linux (Ubuntu 12.04) but not on Windows 7.
msg174384 - (view) Author: Michael Grünewald (michaelgruenewald) Date: 2012-10-31 23:26
Cannot reproduce that with Ubuntu 12.04. Python 2.7 returned ";" under both Windows 7 and Ubuntu 12.04.

Can you verify that there was no space before the semicolon? Otherwise the semicolon gets treated as the beginning of an inline comment.
msg174385 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-10-31 23:47
> Cannot reproduce that with Ubuntu 12.04.

+1.

Attached a reproducer.
msg174498 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2012-11-02 09:20
Well, the inline comment syntax was awkward to start with, that's why inline comments are now disabled by default since Python 3.2.

For a more predictable situation with regard to comment handling, consider using the configparser 3.2+ backport for Python 2.6 and 2.7: http://pypi.python.org/pypi/configparser

As for the original report, Michael is on the right track. Semicolon gets treated as a beginning of an inline comment if it's preceeded by a space, unless it's right after the key-value delimiter. In other words, these are inline comments:

  key1 = value ;inline comment!
  key2 =value ;inline comment!
  key3= value ;inline comment!
  key4=value ;inline comment!
  key5 : value ;inline comment!
  key6 :value ;inline comment!
  key7: value ;inline comment!
  key8:value ;inline comment!

while these are not:

key10 = value;value;value
key11 = value;
key12=;
key13:;
key14=     ;
key15:     ;
key16 =     ;
key17 :     ;
key18 :     ; ;gotcha!

Yes, key18's value is "; ;gotcha!" which is also a quirk of the old ConfigParser. Moreover, # can be used for full-line comments but not for inline comments.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60578
2012-11-02 09:20:42lukasz.langasetstatus: open -> closed
resolution: wont fix
messages: + msg174498
2012-10-31 23:47:02berker.peksagsetfiles: + reproducer.py
nosy: + berker.peksag
messages: + msg174385

2012-10-31 23:26:15michaelgruenewaldsetnosy: + michaelgruenewald
messages: + msg174384
2012-10-31 16:05:29r.david.murraysetnosy: + lukasz.langa
2012-10-31 15:01:50Daniel.Gordoncreate