Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.07; 'wednesday,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; '*only*': 0.16; '-tkc': 0.16; 'container,': 0.16; 'container.': 0.16; 'languages)': 0.16; 'python;': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'sort': 0.25; 'posts': 0.26; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'tim': 0.29; "doesn't": 0.30; 'gives': 0.31; 'chase': 0.31; 'subject:size': 0.31; "can't": 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'read': 0.60; 'dave': 0.60; 'size.': 0.65; 'angel': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Finding size of Variable Date: Wed, 5 Feb 2014 08:43:34 -0500 (EST) Organization: news.gmane.org References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <7e7d3200-a4ae-4842-ad8d-68b4435b9006@googlegroups.com> X-Gmane-NNTP-Posting-Host: dpc6744192046.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391607624 news.xs4all.nl 2842 [2001:888:2000:d::a6]:60277 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65477 Ayushi Dalmia Wrote in message: > On Wednesday, February 5, 2014 12:59:46 AM UTC+5:30, Tim Chase wrote: >> On 2014-02-04 14:21, Dave Angel wrote: >> >> > To get the "total" size of a list of strings, try (untested): >> >> > >> >> > a = sys.getsizeof (mylist ) >> >> > for item in mylist: >> >> > a += sys.getsizeof (item) >> >> >> >> I always find this sort of accumulation weird (well, at least in >> >> Python; it's the *only* way in many other languages) and would write >> >> it as >> >> >> >> a = getsizeof(mylist) + sum(getsizeof(item) for item in mylist) >> >> >> >> -tkc > > This also doesn't gives the true size. I did the following: > > import sys > data=[] > f=open('stopWords.txt','r') > > for line in f: > line=line.split() > data.extend(line) > > print sys.getsizeof(data) > Did you actually READ either of my posts or Tim's? For a container, you can't just use getsizeof on the container. a = sys.getsizeof (data) for item in mylist: a += sys.getsizeof (data) print a -- DaveA