【问题标题】:Python: How much memory does attribute takes? [duplicate]Python:属性需要多少内存? [复制]
【发布时间】:2014-07-04 11:50:21
【问题描述】:

Python 中是否有一个函数可以找出某个属性或变量占用了多少内存?

示例:

a='ThisTakesSeveralBitesOfMemory'
print(a.memoryTaken())

>> 20 b

【问题讨论】:

    标签: python variables memory attributes space


    【解决方案1】:

    您可以使用sys.getsizeof()。它以字节为单位返回。

    >>> a='ThisTakesSeveralBitesOfMemory'
    >>> sys.getsizeof(a)
    50
    

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多