Thursday, July 22, 2010

python: how to get size of an object

use sys.getsizeof:

>>> import sys
>>> x = 2
>>> sys.getsizeof(x)
14
>>> sys.getsizeof(sys.getsizeof)
32
>>> sys.getsizeof('this')
38
>>> sys.getsizeof('this also')
48



source

No comments: