You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: