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

Re: [pygame] Re: Pygame not handling keyboard tracking correctly



On lun, 2014-06-23 at 13:09 +0530, diliup gabadamudalige wrote:
> when you say a=100 and b=100 it is understood that a and b are both
> given TWO values and that both are the same is a coincidence.
> BUT if that is the case how can a is b be TRUE for small integers and
> a is b False for large integers? What logic is Python using here?

As previously mentioned, low integers (0-255 or so, I believe) are
interned when Python starts up. This means they will always refer to the
same object wherever they are used. But, this is an implementation
detail used for optimisation and not something you should rely on in
your code.

If you created the items separately, you cannot assume they are the same
object. They could be the same object, simply depending on how the
internal implementation decides to optimise it, but you should never
rely on it, unless you have taken the direct reference (a = b), or in
the case of strings, used the intern() function to explicitly intern
them.

As I mentioned before, it should be safe to do this with constants, as
you are using the direct reference to the constant itself, and not just
creating an integer of the same value.

Attachment: signature.asc
Description: This is a digitally signed message part