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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM