Error .. Please Help

inshu chauhan insideshoes at
Thu Dec 13 10:23:53 CET 2012

> if-else doesn't define a loop, but each of the for statements do.
> You have defined a classification for 8 of the possible colors, leaving
> millions of them undefined.  If the first time through the loop you
> manage to hit one of those undefined ones, you'll have no value for
> classification.  So you get an exception.

Yes, You are right that I will hit an exception if classification doesnot
have any value.
But as for the colors, actually I myself have colored the image using these
8 colors
but still I think in some pixels I have put more than 1 color, thats why
different colors are being encountered.

> Worse, if you manage to get past that first pixel with a valid
> classification, then for remaining pixels, you'll be using the last
> 'valid' classification encountered.  This is the kind of "quiet failure"
> that programmers dread.  Something that seems to work, but isn't even
> close.

For this I put an else clause at end but is there a better way to avoid
this kind of situation ??

> If you're going to print (to file) on each iteration through the loop
> (except 0,0,0), you need to make sure there's always a valid value.  So
> you need at least one more classification value, and an else clause to
> assign it, as ChrisA pointed out.
> Do you have a reason for treating (0,0,0) specially?  When that value is
> seen, the logic skips the print as well, since continue skips to the
> next loop iteration.

Yes , I have to skip (0,0,0), that is a kind of requirement.

> Are you really getting floating point values, or are they always going
> to be equal to an integer?  Those if/elif statements might be a problem
> if you ever need to compare to a value like (128.4, 255.0, 255.0).

I dont have values with decimal part, All values are integer.

> --
> DaveA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list