Can global variable be passed into Python function?

Marko Rauhamaa marko at pacujo.net
Sun Feb 23 10:24:42 EST 2014


Chris Angelico <rosuav at gmail.com>:

> On Sun, Feb 23, 2014 at 10:01 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> As for Python, there's nothing in the Python specification that would
>> prevent you from having, say, 63-bit integers as representing
>> themselves. IOW, you could physically place such integers as
>> themselves as the reference and the number would not physically exist
>> elsewhere.
>
> What would id(5) be? Some constant? What would id(id([])) be?

Any suitable scheme would do. For example, id(n) == n for 63-bit
integers; other objects are dynamically sequence-numbered starting from
a high base (here, 2 ** 64):

   >>> id(5)
   5
   >>> id([])
   18446744073709551620
   >>> id(id([]))
   18446744073709551624

Or id(n) == 2 * n for 63-bit integers; other objects are dynamically
sequence-numbered using only odd integers starting from 1:

   >>> id(5)
   10
   >>> id([])
   7
   >>> id(id([]))
   18

Or id(n) == 2 ** 64 + n for 63-bit integers; other objects get the
RAM address of the internal ḿemory block:

   >>> id(5)
   18446744073709551621
   >>> id([])
   3074657068
   >>> id(id([]))
   18446744076784207372

The possibilities are endless.


Marko



More information about the Python-list mailing list