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 generating strings I can't compare
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: lpangelrob, tim.peters
Priority: normal Keywords:

Created on 2005-07-08 20:50 by lpangelrob, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg25767 - (view) Author: Robert Guico (lpangelrob) Date: 2005-07-08 20:50
This is better demonstrated than described:

Assume the following "myconfig.cfg" in the current
directory...

[main]
OPT=no
<newline>

The following occurs from the command line:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32
bit (Intel)] on win32
<snip>
>>> from ConfigParser import ConfigParser
>>> p = ConfigParser()
>>> p.read('myconfig.cfg')
['myconfig.cfg']
>>> configWord = p.get('main','OPT')
>>> configWord
'no'
>>> word = 'no'
>>> word
'no'
>>> configWord is word
False
>>> word2 = 'no'
>>> word2
'no'
>>> word2 is word
True
>>> len(word)
2
>>> len(configWord)
2
>>> type(configWord)
<type 'str'>
>>> type(word)
<type 'str'>

In other words, the config values ConfigParser
generates look a lot like strings, have types like
strings, and have the same lengths as strings, but
can't be compared as strings. This smells like a bug.
msg25768 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-07-08 20:57
Logged In: YES 
user_id=31435

You should never use "is" to compare strings for equality 
(unless you have deep knowledge of what you're doing, and 
your application code guarantees to use unique string 
objects).  Use "==" instead.

For more about when you can and can't rely on "is", please 
start a discussion on comp.lang.python (or use Google to 
find the many previous discussions).  It's not "a bug", and 
won't change.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42175
2005-07-08 20:50:34lpangelrobcreate