首页 > 编程语言 > 详细

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

时间:2017-01-03 16:50:46      阅读:250      评论:0      收藏:0      [点我收藏+]

 

 

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

 

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

原文:http://www.cnblogs.com/dadadechengzi/p/6245173.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!