Is there a better way to solve this?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon May 23 20:03:17 EDT 2011
On Mon, 23 May 2011 11:55:08 -0700, kracekumar ramaraju wrote:
> You can use sizeof function,
Who are you talking to, and what question did they ask?
Please always quote enough of the post that you are replying to to
establish context.
>>>> a=12234
>>>> b=23456.8
>>>> a.__sizeof__()
> 12
>>>> b.__sizeof__()
> 16
> So sizeof int is 12 bytes and float is 16 bytes
You shouldn't be calling special methods directly (except under unusual
circumstances). That's like calling s.__len__() instead of len(s).
The public function for getting the size of an object is in the sys
module:
sys.getsizeof(a)
--
Steven
More information about the Python-list
mailing list