[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Constant identity
Pete Shinners <pete@visionart.com>:
>
> Magnus Lie Hetland wrote:
> > I think I've asked about this before, but is it safe to rely on
> > constant identity in Pygame? I.e. is it OK to say
> >
> > if event.type is QUIT: ...
>
> generally it is not safe to do this. equal python integers do not
> necessarily point to to the same python object (which "is" tests for).
I know.
> now in 'real life', python has a 'cache' for all numbers from -1 to
> 99. so all "low integers" will magically point to the same python
> object. this is not 'guaranteed' by any means, but it has always
> been (and will perhaps always be?)
I know.
> sdl only allows for up to NUMEVENT events, which is 32. so this
> logically means any pygame event types will always point to the same
> python object. but this won't work for things like key types, like
> K_DELETE.
>
> therefore:
> event.type is QUIT #not recommended, but works
> event.key is K_BACKSPACE #don't do it
>
> in the python interpreter..
> >>> 10 is 10*1
> 1
> >>> 100 is 100*1
> 0
>
> in the end, stick with the equals operator " == " and everyone wins.
OK. This is what I've used -- I just seemed to remember some special
trickery in Pygame that used the same (identical) numbers... After
all, "is" is used in the monkey tutorial... :)
--
Magnus Lie Hetland The Anygui Project
http://hetland.org http://anygui.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org