negative numbers are not equal...

Mel mwilson at the-wire.com
Fri Aug 15 14:35:34 EDT 2008


castironpi wrote:
> It would be nice to put together a really canonical case of the use of
> the 'is' comparison.  FTSOA for the sake of argument, when do you use
> it?  Why is it even in the language?

My poster child use case is in a MUDD game.  For instance, the player
represented by `this_player` has picked up the yoghurt.  We notify the
other players using code that boils down to:

for person in this_room.inhabitants:
    if person is not this_player:
        person.notify ('%s has picked up the %s.'
                % (this_player.name, 'yoghurt'))

The `is` test avoids telling this_player something he already knows. 
Perhaps the code could be written to make an equality test work, but then
again, perhaps the game could have a much more interesting use for equality
between persons.

        Mel.



More information about the Python-list mailing list