Location of variables

Remco Gerlich scarblac at pino.selwerd.nl
Thu Jan 18 06:43:42 EST 2001


Grzegorz Dostatni <grzegorz at ohaton.cs.ualberta.ca> wrote in comp.lang.python:
> Is there a way in Python to find out the memory location of variables?  
> Something like 
> 
> def s():
> 	pass
> 
> print s
> 
> will print the type and memory location of s.  
> Is there something like that if s is just a simple variable?  
> (int for example).

That address is the id() of s (try print hex(id(s))). You can take the id()
of any object. This is the object's address in the current C implementation
of Python, but I don't know if that's guaranteed to stay.

Insert the appropriate warning lights and stuff here.

-- 
Remco Gerlich



More information about the Python-list mailing list