Re: space effecient representations of list subsets (addendum)

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Fri, 3 Dec 1993 17:12:52 -0500

On Dec 3, 13:31, "Jaap Vermeulen (jaap)" wrote:
>
> What's happening here? The id() function is unique *as long as the object
> lives*. As soon as the object is garbage collected, the same id can be used
> for another object. It still doesn't explain Steven's observation, though:
>
>
> So probably this is an anomaly as Steven points out.
>

I don't think "anomaly" is quite the right word, as it happens *reliably*.

It is an effect of ( I was about to say side effect, but it well may
be intentional ) the code objects that python code is compiled into:

>>> def one():
... return 1
...
>>> one.func_code.co_consts
[None, 1]
>>>

I assume that what this means is that "return 1" really becomes
something more (pseudo-) like "return code.co_consts[1]", and so

>>>if id(1) == id(1) :

really becomes: if id(co_consts[1]) == id(co_consts[1])

[ Obviously, not quite literally - this is my pseudo-python
representation of my guess at the compiled .pyc code
representation, which is probably quite inaccurate in
detail, but, in the context of explaining id(1)==id(1),
if probably close enough.

I was peeking around at the code-object representation back
in the thread about self documenting functions to see if the
args were available somewhere. I haven't had quite the time
to decipher it in enough detail to understand WHAT exactly
is the use and structure of those code attributes structures. ]

- Steve