On Jun 18, 10:07 am, "filox" <[EMAIL PROTECTED]> wrote: > is there a way to find out the size of an object in Python? e.g., how could > i get the size of a list or a tuple? > > -- > You're never too young to have a Vietnam flashback
You can use the struct module to find the size in bytes: import struct mylist = [10, 3.7, "hello"] int_count = 0 float_count = 0 char_count = 0 for elmt in mylist: if type(elmt) == int: int_count += 1 elif type(elmt) == float: float_count += 1 elif type(elmt) == str: char_count += len(elmt) format_string = "%di%dd%dc" % (int_count, float_count, char_count) list_size_in_bytes = struct.calcsize(format_string) print list_size_in_bytes --output:-- 17 -- http://mail.python.org/mailman/listinfo/python-list