0

Hello there,

I am working on pylon frame work, when i am issuing return render('/test.mako'), it is displaying index out of renge error.

Plz Reply to this post if u have any idea in this.

Thanks
ss

5
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by pyTony
0

Here's a general idea of what's happening:

abc = ['a','b','c']
print(abc[3]) #IndexOutOfRange exception
0

Here's a general idea of what's happening:

abc = ['a','b','c']
print(abc[3]) #IndexOutOfRange exception

should be

print(abc[2])

the first item in the index is 0, so the last item should there fore be 2

0

the first item in the index is 0, so the last item should there fore be 2

You missing the point he is showing how an IndexOutOfRange exception happends. print(abc[2]) is off course correct,but that not the point here.

0

The point really is not to use len(a) but len(a)-1 as maximum. This also helps to understand why range(5) gives numbers 0 until 4.

>>> a=['a','b','c']
>>> print a[len(a)]

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    print a[len(a)]
IndexError: list index out of range
>>> for i in range(len(a)):
	print a[i]
	
a
b
c

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.