filox wrote: > "Brett Hoerner" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> On Jun 18, 11: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? >> "Size" can mean a lot of things, >> >> len(my_list) >> len(my_tuple) >> >> Although I have the feeling you mean "how many bytes does this object >> take in memory" - and I believe the short answer is no. >> > > is there a long answer? what i want is to find out the number of bytes the > object takes up in memory (during runtime). since python has a lot of > introspection mechanisms i thought that should be no problem... > >
New-style classes have both a __basicsize__ and an __itemsize__ attribute. __basicsize__ gives the number of bytes in the fixed size portion of an instance. For immutable types with variable size, such as tuple and str, multiply __itemsize__ by the object length and add to __basicsize__ to get the instance size. long type instances also vary in length, but since long has no length property trying to figure out the size of a particular instance is harder. And types like list, map and unicode keep pointers to blocks of memory allocated separately. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list