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


Groups > comp.lang.python > #6097

Re: Is there a better way to solve this?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Is there a better way to solve this?
Date 2011-05-23 18:06 -0400
References <mailman.1906.1306046523.9059.python-list@python.org> <a6f25b6b-ddfe-435a-9035-5f156888d2b5@glegroupsg2000goo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1988.1306189308.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 5/23/2011 2:55 PM, kracekumar ramaraju wrote:
> You can use sizeof function,

Appears not to be in manuals, that I could find. As a special method, it 
is intended to be called through sys.getsizeof.

>>>> a=12234
>>>> b=23456.8
>>>> a.__sizeof__()
> 12
>>>> b.__sizeof__()
> 16
> So sizeof int is 12 bytes and float is 16 bytes

Depends on system. On my winxp machine, ints are 14 bytes.

 >>> import sys
 >>> size = sys.getsizeof
 >>> size(1)
14
 >>> size(1.0)
16
 >>> size([])
36
 >>> size([1,2,3])
48

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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? David Robinow <drobinow@gmail.com> - 2011-05-23 16:27 -0400
  Re: Is there a better way to solve this? Terry Reedy <tjreedy@udel.edu> - 2011-05-23 18:06 -0400

csiph-web