[New-bugs-announce] [issue13427] string comparison with ==

Alan Beccati report at bugs.python.org
Fri Nov 18 12:43:55 CET 2011

New submission from Alan Beccati <alan.beccati at gmail.com>:

did I discover a python string comparison bug or is this behaviour expected and I am doing something wrong?

This is the code I run:
for line in lines[4:]:
	print "'",currColl,"'","==","'",collName,"'"
	if currColl == collName :
		return True
		print "not equal"

where currColl is a method parameter and lines is built from subprocess Popen like:
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
The output of the abovementioned code is:
' utm ' == ' utm10 '
not equal
' utm1000 ' == ' utm10 '
not equal
' utm100 ' == ' utm10 '
not equal
' utm10 ' == ' utm10 '
not equal
' utm1 ' == ' utm10 '
not equal

as you can see the fourth comparison should return True while it gives a "not equal" as the others.

Python info:
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2

messages: 147854
nosy: Alan.Beccati
priority: normal
severity: normal
status: open
title: string comparison with ==
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list