is there a function in Python which can find out how much memory takes a certain attribute or a variable?

EXAMPLE:

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

>> 20 b
有帮助吗?

解决方案

You can use sys.getsizeof(). It returns in bytes.

>>> a='ThisTakesSeveralBitesOfMemory'
>>> sys.getsizeof(a)
50
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top