1

Just started programming python. I have a question with this error IndexError: tuple index out of range. This app is somewhat reading large amount of log files.

my example list is:

arrline = ['Array0', 'Array1', 'Array2', 'Array3', 'Array4', 'Array5', 'Array6:', 'Array7', 'Array8', 'Array9', 'Array10', 'Array11', 'Array12', 'Array13', 'Array14', 'Array15', 'Array16']

when I use

tmp1 = '{0}{1}{12}{5}{6}{17}'.format(*arrline)
print tmp1

I end up getting IndexError: tuple index out of range.

but when I try

tmp1 = '{0}{1}{2}{3}{4}{5}'.format(*arrline)

It doesn't get any errors.

Any help is greatly appreciated.

1
  • 2
    {17} would need arrline to have 18 items at least. Commented Feb 20, 2017 at 10:24

2 Answers 2

2

IndexError: tuple index out of range.

This error tries to tell you that you're trying to get an object from the tuple which is not in the index range of the defined tuple. The {17} which you're trying to print doesn't exist!

But your code which request items up until {5} can be executed because of the 16 items in the tuple!

Try to add another item to your tuple, or change {17} to {16}

Sign up to request clarification or add additional context in comments.

Comments

0

Because your array contains 17 elements but according to array indexing it's 0-16, Array Index always starts from 0 so as you are using {17} , This index is not available you start counting from 0 , That's why your getting error {17} while tmp1 = '{0}{1}{12}{5}{6}{17}'.format(*arrline)'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.