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

Recommended Answers

All 4 Replies

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

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

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

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.