0

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
user3620512
  • 39
  • 1
  • 8

1 Answers1

0

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

>>> a='ThisTakesSeveralBitesOfMemory'
>>> sys.getsizeof(a)
50
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218