Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.058 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'subject:not': 0.03; 'modifying': 0.07; 'iterate': 0.09; 'pixel': 0.09; 'second.': 0.09; 'cc:addr:python-list': 0.11; '>>': 0.16; 'data...': 0.16; 'in-memory': 0.16; 'iterated': 0.16; 'once.': 0.16; 'traverse': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'file,': 0.19; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'parse': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'suggested': 0.26; 'read,': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'lines': 0.31; 'once,': 0.31; 'file': 0.32; 'option': 0.32; 'another': 0.32; 'text': 0.33; 'open': 0.33; '(e.g.': 0.33; 'fri,': 0.33; 'knows': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; "he's": 0.36; 'object,': 0.36; 'done': 0.36; 'useful': 0.36; 'should': 0.36; 'half': 0.37; 'so,': 0.37; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'pm,': 0.38; 'anything': 0.39; 'how': 0.40; 'read': 0.60; 'easy': 0.60; 'full': 0.61; 'new': 0.61; 'course': 0.61; 'first': 0.61; 'information': 0.63; 'more': 0.64; 'taking': 0.65; '(that': 0.65; 'talking': 0.65; 'close': 0.67; 'yes': 0.68; '26,': 0.68; '500': 0.70; 'touch': 0.74; 'subject:For': 0.78; 'otten': 0.84; 'to:none': 0.92; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:cc:content-type; bh=7/NxwqlY937//uBu4IGlT1bzsPqvJiWunJzWxDYOONQ=; b=IOEAsf3s37TibFdQ7QlJwH8PF1QFg4+tTl/Ck975hoTDvgHoh220tMCSeQYrs3Iswh bh6SRdxlG2xNNpxM0OGRDTe5pzuXnpU2cZLb8ZKGb2iMJsp3IwfooQR1L/W4mT1w78eN XYRru//zGEUyjLAth4TZLHdR7CqKMc4nUs+h3l3OjORyT12L8hw6tpTFp4P4crMcSuFz oXzaXUq9FZWF4CrrTxEf5/8BuAQSCdMpQa4IYvOJ25trBryUooeVy6G47c7CHYHbx94B VrcfS6uq45do5VPq7TKsKxu+jrFeRosW1ttQs2Mym8BqlXayVFNkwAajoFn/0J2VEwLE f8fQ== MIME-Version: 1.0 X-Received: by 10.42.64.135 with SMTP id g7mr23870590ici.37.1366982448379; Fri, 26 Apr 2013 06:20:48 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Apr 2013 18:50:48 +0530 Subject: Re: Nested For loop not running full From: inshu chauhan Cc: "python-list@python.org" Content-Type: multipart/alternative; boundary=90e6ba5bbaa3401c0604db4367ff 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: 128 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366982457 news.xs4all.nl 15904 [2001:888:2000:d::a6]:57086 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44406 --90e6ba5bbaa3401c0604db4367ff Content-Type: text/plain; charset=ISO-8859-1 , 2013 at 3:15 PM, Chris Angelico wrote: > On Fri, Apr 26, 2013 at 7:36 PM, inshu chauhan > wrote: > > > > On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__@web.de> wrote: > >> > >> f = open(...) > >> > >> in the code you are not showing with > >> > >> f == list(open(...)) > > > > f is just a text file(csv format).. so why list ?? > > (That should be =, not ==) > > Instead of having an open file object, you would instead have a list > of the lines in the file. That can be iterated over more than once. > > >> The reasonable thing to do is of course to move the preprocessing (e.g. > >> csv- > >> parsing) out of the sy and sx loops. > > > > > > I did this but again then what I intend to do is not really happening, > For > > every pixel I read, I want to traverse the full file, so that the > > information I am taking from pixel have to match in one of the line in > the > > file. Can this be done by modifying my code ? or something new has to be > > devised ? > > How large is the file? There are two easy solutions: > > 1) Open and close the file every time you touch a pixel > 2) Open the file once, read it all into memory, and then iterate over > the in-memory copy every pixel > > If your file is insanely large then the first option may be better, > but for anything less than five yottabytes, go with the second. (Okay, > I may be exaggerating slightly... let's say anything less than half > your RAM. So if you have 10YB of memory, then I wasn't exaggerating.) > That's why Peter suggested creating a list; you iterate over the list. > Another way to do it is to parse the file once and retain a more > efficient and useful structured form of the data... which is the other > thing Peter suggested ("move the preprocessing (e.g. csv- > parsing) out of the sy and sx loops"). > > So, yeah. Listen to Peter Otten, he knows what he's talking about :) > > ChrisA > Yes I am trying Peter's way and my file is just 500 KB .. :) --90e6ba5bbaa3401c0604db4367ff Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
, 2013 at 3:15 PM, Chris Angelico <rosuav@gmail.com>= ; wrote:
On Fri, Apr 26, 2013 at 7:36 PM, inshu chauhan <insideshoes@gmail.com> wrote:
>
> On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__@web.de> wrote:
>>
>> f =3D open(...)
>>
>> in the code you are not showing with
>>
>> f =3D=3D list(open(...))
>
> f is just a text file(csv format).. so why list ??

(That should be =3D, not =3D=3D)

Instead of having an open file object, you would instead have a list
of the lines in the file. That can be iterated over more than once.

>> The reasonable thing to do is of course to move the preprocessing = (e.g.
>> csv-
>> parsing) out of the sy and sx loops.
>
>
> I did this but again then what I intend to do is not really happening,= For
> every pixel I read, =A0I want to traverse the full file, so that the > information I am taking from pixel have to match in one of the line in= the
> file. Can this be done by modifying my code ? or something new has to = be
> devised ?

How large is the file? There are two easy solutions:

1) Open and close the file every time you touch a pixel
2) Open the file once, read it all into memory, and then iterate over
the in-memory copy every pixel

If your file is insanely large then the first option may be better,
but for anything less than five yottabytes, go with the second. (Okay,
I may be exaggerating slightly... let's say anything less than half
your RAM. So if you have 10YB of memory, then I wasn't exaggerating.) That's why Peter suggested creating a list; you iterate over the list.<= br> Another way to do it is to parse the file once and retain a more
efficient and useful structured form of the data... which is the other
thing Peter suggested ("move the preprocessing (e.g. csv-
parsing) out of the sy and sx loops").

So, yeah. Listen to Peter Otten, he knows what he's talking about :)
ChrisA

Yes I am trying Peter'= s way and my file is just 500 KB .. :)
--90e6ba5bbaa3401c0604db4367ff--