[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pygame] Odd key code behaviour



I always wondered why Python even included "is".
Given "explicit is better than implicit" and 
the anti-TMTOWTDI senitments, I'd think that
the explict:
	id(x) == id(y)
is much better than:
	x is y.

I always do this when I want to compare object
identity because it's so much more self documenting.

m

-----Original Message-----
From: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org]On
Behalf Of Pete Shinners
Sent: Friday, January 25, 2002 1:06 PM
To: pygame-users@seul.org
Subject: Re: [pygame] Odd key code behaviour


Magnus Lie Hetland wrote:
> I just had a lot of trouble with K_UP... K_TAB worked just fine, but
> not K_UP. Then I started to suspect that the trouble was that I was
> using "event.key is K_UP" and not "event.key == K_UP". The latter is
> safer, of course, but I assumed that K_UP had been used in generating
> the event... After all, "event.key is K_TAB" worked just fine.
> 
> What is the difference between the two? Good/bad luck? :)

yes, the difference is how the "is" operator works in python. it is 
actually a test if two variables point to the exact same object (not 
just two objects with the same value).

things start to get a little confusing because python does a lot of 
caching of integers and strings, so sometimes two unique constant values 
will be true for "is" and sometimes they will not be.

i believe the "is" comparison will always be consistent. so if it 
returns true once, that test will always return true.



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org