How do I determine the size of an object in Python?

前端 未结 13 1466
半阙折子戏
半阙折子戏 2020-11-21 21:53

I want to know how to get size of objects like a string, integer, etc. in Python.

Related question: How many bytes per element are there in a Python list (tuple)?

13条回答
  •  旧巷少年郎
    2020-11-21 22:57

    Here is a quick script I wrote based on the previous answers to list sizes of all variables

    for i in dir():
        print (i, sys.getsizeof(eval(i)) )
    

提交回复
热议问题