Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6087 > unrolled thread

Re: Is there a better way to solve this?

Started bykracekumar ramaraju <kracethekingmaker@gmail.com>
First post2011-05-23 11:55 -0700
Last post2011-05-24 00:03 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Re: Is there a better way to solve this? kracekumar ramaraju <kracethekingmaker@gmail.com> - 2011-05-23 11:55 -0700
    Re: Is there a better way to solve this? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-24 00:03 +0000

#6087 — Re: Is there a better way to solve this?

Fromkracekumar ramaraju <kracethekingmaker@gmail.com>
Date2011-05-23 11:55 -0700
SubjectRe: Is there a better way to solve this?
Message-ID<mailman.1983.1306176915.9059.python-list@python.org>
You can use sizeof function,
>>> a=12234
>>> b=23456.8
>>> a.__sizeof__()
12
>>> b.__sizeof__()
16
So sizeof int is 12 bytes and float is 16 bytes

[toc] | [next] | [standalone]


#6102

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-05-24 00:03 +0000
Message-ID<4ddaf5c4$0$29996$c3e8da3$5496439d@news.astraweb.com>
In reply to#6087
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web