Stringify object reference?

Manuel M. Garcia mgarcia at cole-switches.com
Fri Oct 11 14:31:32 EDT 2002


On Fri, 11 Oct 2002 18:17:33 +0100, Alan Kennedy <alanmk at hotmail.com>
wrote:

>Is there a specific reason why id()'s can't be turned back into objects?
>Is it an implementation specific thing? Or is it to stop people messing
>with pointers, etc?

Yup, allowing this would give Python a general pointer capability,
which would allow crashes when mistakes are made if implemented like
in C.  If robustly implemented, all the consistency checks would make
operations with them as slow as (if not slower than) normal Python
types and classes.
Just throw everything into a dictionary or list, and use the index or
key as a pointer.  You even have the ability to pickle this dictionary
or list so you can continue where you left off in a later session,
which would be impossible with "real" pointers, because the memory
allocator places things arbitrarily where convenient with each
session.



More information about the Python-list mailing list