Why doesn't the following string comparison work? I have the following code (I adapted it to make it easier). I extract the player from the database and add him to the list of players. Then I loop into the list of players and try to find it, and even though the string is the same, the comparison returns false.
def findPlayer2(self, protocol, playerId): cur = self.conn.cursor() cur.execute("SELECT playerId, playerName, rating FROM players WHERE playerId LIKE (%s)", [playerId]) nbResult = cur.rowcount result = cur.fetchone() cur.close() if nbResult > 0: player = Player(protocol, str(result[0]), str(result[1]), result[2]) self.players.append(player) for player in self.players: id1 = str(player.playerId) id2 = str(playerId) print type(id1) print type(id2) print "Comparing '%s' with '%s'" % (id1, id2)
Give the following result:
<type 'str'> <type 'str'> Comparing '11111111' with '11111111' Not equal :(
source share