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


Groups > comp.lang.python > #33603

Re: Error

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'value,': 0.03; 'error:': 0.05; 'attributes': 0.07; 'exception.': 0.07; 'subject:Error': 0.07; 'second.': 0.09; 'tuple': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'index': 0.13; 'stack': 0.15; '0.0,': 0.16; '1000):': 0.16; 'assignments,': 0.16; 'dist': 0.16; 'element,': 0.16; 'idx': 0.16; 'range.': 0.16; 'subscripting': 0.16; 'trace.': 0.16; 'zero,': 0.16; 'wrote:': 0.17; 'element': 0.17; 'changes': 0.20; 'causing': 0.20; 'skip:" 30': 0.20; 'meant': 0.21; 'assuming': 0.22; 'cc:2**0': 0.23; 'statement': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'am,': 0.27; 'separate': 0.27; 'possible,': 0.27; "doesn't": 0.28; 'points': 0.29; 'classes': 0.30; 'error': 0.30; 'figure': 0.30; 'on,': 0.30; 'point': 0.31; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'dies': 0.33; 'ones,': 0.33; 'traceback': 0.33; 'another': 0.33; 'list': 0.35; 'false': 0.35; 'continue': 0.35; 'but': 0.36; 'too': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'two': 0.37; 'item': 0.37; 'well.': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'things': 0.38; 'received:192': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'range': 0.60; 'most': 0.61; 'first': 0.61; 'kind': 0.61; 'close': 0.63; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; '71,': 0.84; 'received:74.208.4.194': 0.84; 'items,': 0.91; 'exceeded': 0.97
Date Tue, 20 Nov 2012 08:01:52 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To inshu chauhan <insideshoes@gmail.com>
Subject Re: Error
References <CAFqGZRGYDM_3H657gid9GUxrSbnM_92nCZEsWWcWhFua5xEpmw@mail.gmail.com> <50A3E794.7080900@mrabarnett.plus.com> <CAFqGZRFmj7+HoYn-t_kD-Sf9y6WOA3PJAqYjTEnz5PO+HzcDBw@mail.gmail.com> <CAFqGZRE6XiPc0koNXk8HtwNYy2od7oT+qtgt5yBp3iK=_bxXuw@mail.gmail.com>
In-Reply-To <CAFqGZRE6XiPc0koNXk8HtwNYy2od7oT+qtgt5yBp3iK=_bxXuw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:Y7KYQDDdYnFX2/noBh2WE93ixI71oa9BV4zXhI+tFU4 lo/uX04wT4auBNeBIwQZ4gbGt9ElAFVZ6MHnG30N1edRjP9Kmr J0z2I5dnUBMzdo1LUFx1ydcCVfyoDmr0a5SbREVndHkuhtqADF Tp6Rk744++SOvVfojlzVXWwTpo+IaKKRR6Tm5zqA6iXPtamlGi 5BwaCSEh9FUE6a11hTO4zX9cl0YbYxDtKxxpdSP/RvMoTiyYQ+ 8ee7uA+NJhvsAQatm8lQOzbjfNYokWLs0+l/eKx/PTR0ugDom+ zsrvzyOaKLz6Dob3E7SMuGdv3AIxA+FwlQxQXjijUi6WKNoOA= =
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.44.1353416529.29569.python-list@python.org> (permalink)
Lines 91
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353416529 news.xs4all.nl 6874 [2001:888:2000:d::a6]:53971
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33603

Show key headers only | View raw


On 11/20/2012 07:31 AM, inshu chauhan wrote:
> I did the following changes in this part of my programme.. now the
> refereence error is removed but its showing me another error :
>
> def ComputeClasses(data):
>     radius = .5
>     points = []
>     for cy in xrange(0, data.height):
>         for cx in xrange(0, data.width):
>
>             if data[cy,cx] == (0.0,0.0,0.0):
>                 continue
>             else :
>                 centre = data[cy, cx]
>                 print centre
>                 points.append(centre)
>
>
>             change = True
>
>             while change:
>
>                 for ring_number in xrange(1, 1000):
>                     change = False
>                     new_indices = GenerateRing(cx, cy, ring_number)
>
>                     for idx in new_indices:
>                         point = data[idx[0], idx[1]]
>
>                         if point == (0.0, 0.0, 0.0 ):
>                           continue
>                         else:
>
>                             dist = distance(centre, point)
>                             if  dist < radius :
>                                 print point
>                                 points.append(point)
>                                 change = True
>                                 print change
>
>
>                 break
>
>
>             print points
>
>
> ERROR :
>
> Traceback (most recent call last):
>   File "Z:/modules/classification1.py", line 71, in <module>
>     ComputeClasses(data)
>   File "Z:/modules/classification1.py", line 47, in ComputeClasses
>     point = data[idx[0], idx[1]]
> error: index is out of range
>
> What is meant by this statement ' Index out of range ' ? Does it mean that
> my range 1, 1000 is exceeded ??
>
>

When you're using custom classes that mimic the standard ones, the error
can mean most anything.  But assuming the design was to keep as close as
possible, it simply means that you're subscripting a list with an index
that's too large or too small.  So if idx is a list that has only one
element, element number zero, then idx[1] would be out of range.  On the
same line, if data is acting kind of like a two-dimensional list, then
it has limits on each dimension, and either idx[0] is too big/small for
the first dimension, or idx[1] is too big or small for the second.

First thing is to figure out which part of this expression is causing
the exception.  So do a separate pair of assignments,
    dummy0 = idx[0]
    dummy1 = idx[1]

and then  point = data[dummy0, dummy1]

Incidentally, if idx is a tuple or a list, of exactly two items, then
you could just say
       point = data[*idx]

Anyway, if that still doesn't make things clear, then print dummy0 and
dummy1 before the point= line.  That way you can see the last value, the
one it dies on, just before the stack trace.  Naturally, you could also
print the size attributes of the data item as well.


-- 

DaveA

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


Thread

Re: Error Dave Angel <d@davea.name> - 2012-11-20 08:01 -0500

csiph-web