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

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