error

Dave Angel d at davea.name
Tue Nov 6 14:05:50 CET 2012


On 11/06/2012 07:31 AM, inshu chauhan wrote:
> I am getting this error while running my programme.. :
>
> error: index is out of range

Please paste the whole error, including the traceback.  It'll show you
the line that had the error, as well as the calling sequence that got
you there.

>
>  I cannot find a valid reason for it in my prog can somebody suggest what
> may be possible reasons for this error..
>
> The part of the code is :
>
> def addpoints (data, points, ix, iy): # makes a list of relevant points
>     if 0 < ix < data.width and 0 < iy < data.height:
>         point = data[ix, iy]

Tell us the type of the parameters.  Perhaps data is of type Zanzibar, 
and the first subscript is the height, and the second is the width? 
Show us your class definition, since data is obviously not a built-in
collection.

>         if point != (0.0, 0.0, 0.0):
>             points.append(point)
>     return points
>
> for dx in xrange(-mask_size2, mask_size2 + 1):
>         for dy in xrange(-mask_size2, mask_size2 + 1):

What is the meaning and value of mask_size2 ?  Is it a negative int?

>             ix, iy = x + dx, y + dy
>             addpoints(data, points, ix , iy )
>
>

BTW, this function's initial comment is incorrect.  It doesn't make a
list, it appends to one passed in.  And there's no point in returning
that list, since it has already been modified.  By good convention, a
simple function either returns a result or modifies its parameter, it
shouldn't do both.  Obviously there are exceptions for complex
functions, but even then, for a single collection, it should either be
modified in place, or created and returned, not both.

-- 

DaveA



More information about the Python-list mailing list