''' object_size.py
get the size of a Python object in memory
tested with Python27 and Python33  by  vegaseat  22oct2013
'''

import sys

mytuple = ()
mylist = []
mydict = {}
mystr = "" 
 
print("Size of empty tuple = {}".format(sys.getsizeof(mytuple)))
print("Size of empty list = {}".format(sys.getsizeof(mylist))) 
print("Size of empty dictionary = {}".format(sys.getsizeof(mydict))) 
print("Size of empty string = {}".format(sys.getsizeof(mystr))) 

''' 
result (Python27, 32 bit version) ...
Size of empty tuple = 28
Size of empty list = 36
Size of empty dictionary = 140
Size of empty string = 21

result (Python33, 32 bit version) ...
Size of empty tuple = 28
Size of empty list = 36
Size of empty dictionary = 148
Size of empty string = 25
'''
4
Contributors
3
Replies
26
Views
3 Years
Discussion Span
Last Post by DarkPikachu
1

64 bit, Python 2.7 is predictably twice the memory, except for the string???

"""
Size of empty tuple = 56
Size of empty list = 72
Size of empty dictionary = 280
Size of empty string = 37
"""
1

64 bit, Python 3.2.3:

Size of empty tuple = 28
Size of empty list = 36
Size of empty dictionary = 140
Size of empty string = 30
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.