[ python-Bugs-1234965 ] ConfigParser generating strings I can't compare
SourceForge.net
noreply at sourceforge.net
Fri Jul 8 22:57:21 CEST 2005
Bugs item #1234965, was opened at 2005-07-08 16:50
Message generated for change (Comment added) made by tim_one
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1234965&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Robert Guico (lpangelrob)
Assigned to: Nobody/Anonymous (nobody)
Summary: ConfigParser generating strings I can't compare
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2005-07-08 16:57
Message:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1234965&group_id=5470
More information about the Python-bugs-list
mailing list