Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:04:23+00:00 2026-05-24T12:04:23+00:00

#!/usr/bin/python import os,sys from os import path input = open(‘/home/XXXXXX/ERR001268_1’, ‘r’).read().split(‘\n’) at = 1

  • 0
#!/usr/bin/python

import os,sys
from os import path

input = open('/home/XXXXXX/ERR001268_1', 'r').read().split('\n')

at = 1
for lines in range(0, len(input)):
    line1 = input[lines]
    line4 = input[lines+3]
    num1 = line1.split(':')[4].split()[0]
    num4 = line4.split(':')[4].split()[0]
    print num1,num4


    at += 1

However I got the error: list index out of range

What’s the problem here?

btw, besides "at +=1", is there any other way to finish this cycle loop?
thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:04:23+00:00Added an answer on May 24, 2026 at 12:04 pm

    Lets say len(input) == 10. range(0, len(input)) iterates [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. And when lines > 6 and you’re trying to access input[lines+3], it clearly an IndexError, because there is no index[10], [11] etc .

    And line1.split(':')[4] can also raise an IndexError if line1.count(":") < 4.

    I didn’t understand the last at part, it seems not doing anything, but you can break the loop easily with break statement.

    Also, naming a variable input is a bad idea because it conflicts with builtin input function. And range(0, len(input)) == range(len(input)), so 0 as range’s first argument is unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, here's my script: #!/usr/bin/python import sys, os sys.path.append('/home/username/python') sys.path.append(/home/username/python/flup) sys.path.append(/home/username/python/django) # more path
Simple code demonstrating the problem: #!/usr/bin/env python import sys from PyQt4.QtCore import QObject, SIGNAL
here is my code #!/usr/bin/python # -*- coding:utf-8 -*- import sys import pysvn def
So I found this code: #!/usr/bin/python import sys #for cmd line argv import time
I'm writing a simple alarm utility in Python. #!/usr/bin/python import time import subprocess import
I'm attempting a pretty cut & dry example of anydbm: #!/usr/bin/python import anydbm #
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter import twitter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent=parent
e.g., how can I find out that the executable has been installed in /usr/bin/python
My code: #!/usr/bin/env python def Runaaall(aaa): Objects9(1.0, 2.0) def Objects9(aaa1, aaa2): If aaa2 !=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.