[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] newb: importing pygame



On 5/17/06, altern <altern2@xxxxxxxxx> wrote:
the code would be much nicer to read like this :

for e in pygame.event.get():
        if e.type is QUIT:
        elif e.type is KEYUP:
        elif e.type is MOUSEBUTTONDOWN:
        # ...

This has nothing to do with the original topic, but just a warning: you should never use the 'is' comparison with integers (like the pygame event codes). Only use it when you really want to test for object identity, because:

a = 1234
a is 1234
False

Both 1234 literals in the above code create a new integer object, so
they have different identity and 'is' comparison fails. Small integer
objects are cached and reused, but you shouldn't count on this
behavior.

--
Sami Hangaslammi