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…
getsizeof的局限 python非内置数据类型的对象无法用sys.getsizeof()获得真实的大小,例: import networkx as nx import sys G = nx.Graph() l = [i for i in xrange(10000)] print "size of l:", sys.getsizeof(l) G.add_nodes_from(l) print "size of graph:", sys.getsizeof(G)…