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


Groups > comp.lang.python > #44403

Re: Nested For loop not running full

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.063
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'subject:not': 0.03; 'modifying': 0.07; 'iterate': 0.09; 'pixel': 0.09; 'second.': 0.09; 'data...': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'in-memory': 0.16; 'iterated': 0.16; 'once.': 0.16; 'traverse': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'creating': 0.23; 'parse': 0.24; 'file.': 0.24; 'suggested': 0.26; 'read,': 0.26; 'header:In-Reply-To:1': 0.27; '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; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 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; '26,': 0.68; 'touch': 0.74; 'subject:For': 0.78; 'otten': 0.84; '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:to:content-type; bh=+1eiv9WcmfVOarkqQgz/ktbd2RMJdf05FignIxeN6TU=; b=un1pqoA8nITganVdMMhTfcTxPsYCqMz+pFeY2ab+SlDXT1ygDYI0wITWVff+Zxou4F IBapBDuzWOWg334A5Y0Vgk2QR/mgdEEd46eWw14lFHVE+kX+nJ1FxoH2DNzX8XFaQwXN f3jBI6IKlt87HWt+rSIGsK70Zcm7YyIjCtuAZdl9RGHQaQEzuec4m/ifYD1y+RFWkIbg UCDtHEXs3kLr7A4ac7m7Tbm6OEWQpF6LJkqNWOJ0/QYpIJVjiZksULcCphOO2nFYfLrm O0yoMv9hfPo+8s/rkR0MF6QrOutRzILGOeVrgkV89MuxJkJy9q7F7DAGlfXaBIhGzahX sIzw==
MIME-Version 1.0
X-Received by 10.58.56.161 with SMTP id b1mr28969498veq.42.1366969551684; Fri, 26 Apr 2013 02:45:51 -0700 (PDT)
In-Reply-To <CAFqGZRGoh=hTG7PZgxNaaKgq8Z_QHyqVQZ+voe1z_KY+-ysjug@mail.gmail.com>
References <CAFqGZRF4s_+9R4qDZTmFD7OWWMTn_YnhjKNMh8gY97ng5tyr9g@mail.gmail.com> <kldg7b$20b$1@ger.gmane.org> <CAFqGZRGoh=hTG7PZgxNaaKgq8Z_QHyqVQZ+voe1z_KY+-ysjug@mail.gmail.com>
Date Fri, 26 Apr 2013 19:45:51 +1000
Subject Re: Nested For loop not running full
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1092.1366969559.3114.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366969559 news.xs4all.nl 15936 [2001:888:2000:d::a6]:49221
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44403

Show key headers only | View raw


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 = 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

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


Thread

Re: Nested For loop not running full Chris Angelico <rosuav@gmail.com> - 2013-04-26 19:45 +1000

csiph-web