Help: sizeof() and reference in python?

Ken Seehof kens at
Sun Mar 5 22:39:37 CET 2000

Gene Chiaramonte wrote:

> Is there a way to get the size of an object in python? I'd also like to get
> a reference to an object.

Yeah, but you'd have to write it as a C extension and it would be a
rather difficult project.  I wonder if this has been done.  In a high-level
language like python, people rarely need things like sizeof.

> example in c:
> l = [1, 2, 3]   #python list
> t1 = sizeof(l)  // how i'd do it in c

Be careful: The python list is implemented as an array of pointersto objects.
In this case, the objects are pre-allocated integer constants
(because they are small), and in any case the objects themselves are
not part of the memory usage of the list.

> t2 = &l

Everything is a reference already (if you are thinking low-level).But this is
misleading because '=' is not an assignment operator,
(except when following a subscript, or in some cases an attribute).
If you are confused by what I am saying, that's a good start.

I recommend spending some quality time with your interpreter
trying different things till you understand exactly what '=' does.

> Thanks,
> Gene

More information about the Python-list mailing list