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


Groups > comp.lang.python > #44406

Re: Nested For loop not running full

References <CAFqGZRF4s_+9R4qDZTmFD7OWWMTn_YnhjKNMh8gY97ng5tyr9g@mail.gmail.com> <kldg7b$20b$1@ger.gmane.org> <CAFqGZRGoh=hTG7PZgxNaaKgq8Z_QHyqVQZ+voe1z_KY+-ysjug@mail.gmail.com> <CAPTjJmpKrQzu3W76FFOw6zOvGEjiHCD6mxuz=5Uz92-c4F64oA@mail.gmail.com>
Date 2013-04-26 18:50 +0530
Subject Re: Nested For loop not running full
From inshu chauhan <insideshoes@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1095.1366982457.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

, 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 = 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 .. :)

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


Thread

Re: Nested For loop not running full inshu chauhan <insideshoes@gmail.com> - 2013-04-26 18:50 +0530

csiph-web