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


Groups > comp.lang.python > #32816

Re: error

Date 2012-11-06 08:05 -0500
From Dave Angel <d@davea.name>
Subject Re: error
References <CAFqGZRFPVdtXvEV0xMEDXG=7KCtKyNwd4Vq6VvDk3CPwW1n5fA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3320.1352207175.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Re: error Dave Angel <d@davea.name> - 2012-11-06 08:05 -0500
  Re: error woooee <woooee@gmail.com> - 2012-11-06 11:59 -0800
    Re: error Dave Angel <d@davea.name> - 2012-11-08 11:33 -0500
    Re: error Jerry Hill <malaclypse2@gmail.com> - 2012-11-08 11:41 -0500
    Re: error inshu chauhan <insideshoes@gmail.com> - 2012-11-09 11:53 +0100
    Re: error inshu chauhan <insideshoes@gmail.com> - 2012-11-09 12:47 +0100
    Re: error inshu chauhan <insideshoes@gmail.com> - 2012-11-09 14:59 +0100
    Re: error inshu chauhan <insideshoes@gmail.com> - 2012-11-09 15:08 +0100
    Re: error Dave Angel <d@davea.name> - 2012-11-12 10:04 -0500

csiph-web