【发布时间】:2014-07-04 11:50:21
【问题描述】:
Python 中是否有一个函数可以找出某个属性或变量占用了多少内存?
示例:
a='ThisTakesSeveralBitesOfMemory'
print(a.memoryTaken())
>> 20 b
【问题讨论】:
标签: python variables memory attributes space
Python 中是否有一个函数可以找出某个属性或变量占用了多少内存?
示例:
a='ThisTakesSeveralBitesOfMemory'
print(a.memoryTaken())
>> 20 b
【问题讨论】:
标签: python variables memory attributes space
您可以使用sys.getsizeof()。它以字节为单位返回。
>>> a='ThisTakesSeveralBitesOfMemory'
>>> sys.getsizeof(a)
50
【讨论】: