Python 获得对象内存占用内存大小 sys.getsizeof

 

 

from sys import getsizeof
   
class A(object): pass
class B: pass

for x in (None, 1, 1L, 1.2, 'c', [], (), {}, set(), B, B(), A, A()):
  print "{0:20s}\t{1:d}".format(type(x).__name__, sys.getsizeof(x))



NoneType                16
int                     24
long                    28
float                   24
str                     34
list                    64
tuple                   48
dict                    272
set                     224
classobj                96
instance                64
type                    896
A                       56

 

posted on 2017-01-03 15:49  大大的橙子  阅读(14116)  评论(0编辑  收藏  举报

导航