<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <span dir="ltr"><<a href="mailto:__peter__@web.de" target="_blank">__peter__@web.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">inshu chauhan wrote:<br>
<br>
> I have this part of my code where I am trying to traverse over an image by<br>
> running a for loop for both x and y co-ordinate axis. But the loop is<br>
> terminating by just reading first pixel. Can think of a reason why this is<br>
> happening ?<br>
><br>
> The code is:<br>
> for sy in xrange(0, segimage.height):<br>
>     for sx in xrange(0, segimage.width):<br>
>             if segimage[sy,sx] == (0.0, 0.0, 0.0):<br>
>                 continue<br>
>             else:<br>
>                 seg_color = segimage[sy,sx]<br>
>                 blue = int(seg_color[0])<br>
>                 green = int(seg_color[1])<br>
>                 red = int(seg_color[2])<br>
>                 reg_num = blue + 256 * green + 65536 * red<br>
>                 for l in f:<br>
>                     sp = l.split(",")<br>
>                     if len(sp) == 14:<br>
>                         print sy, sx  # for checking which pixel its<br>
> reading currently<br>
>                         print reg_num, sp[0]  # for checking whats<br>
> happening<br>
>                         if reg_num == int(sp[0].strip()):<br>
>                             print reg_num, sp[0].strip() # for checking<br>
> whats happening<br>
>                             classification = int(sp[13].strip())<br>
><br>
><br>
> The inside "for loop" is for reading a csv format file from which I am<br>
> extracting some information.<br>
<br>
</div></div>My crystal ball says that the 'for sy...' and 'for sx...' loops are running<br>
to completion, but you don't get the coordinates printed because you put<br>
them into the 'for l in f' loop which will only run once.<br></blockquote><div><br></div><div style>Is there any means by which I can run this 'For l in f' loop again and again ?  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
The quick and dirty fix is to replace<br>
<br>
f = open(...)<br>
<br>
in the code you are not showing with<br>
<br>
f == list(open(...))<br></blockquote><div> </div><div style>f is just a text file(csv format).. so why list ??</div><div style> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

The reasonable thing to do is of course to move the preprocessing (e.g. csv-<br>
parsing) out of the sy and sx loops.<br></blockquote><div><br></div><div style>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 ?</div>
<div style><br></div><div style><br></div><div style><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div></div>