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

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



Thank you very much to all. Now very clear.
May you be well.


On Mon, Jun 23, 2014 at 1:27 PM, Sam Bull <sam.hacking@xxxxxxxx> wrote:
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.



--
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************