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

  • SEARCH
  • Home
  • 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 8463933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:35:16+00:00 2026-06-10T14:35:16+00:00

What I am trying to do is read a line from one file to

  • 0

What I am trying to do is read a line from one file to a string, then search another file for the line that contains that string and parse that line with .split().

My code looks like this:

for line in portslist:
    marker = line.split()
    printername = marker[0]
    address = marker[1]

    for lines in constantfile:
        if address in line: #if the desired address is in the line
            lineholder = line
            lineholder = lineholder.split()
            oldonline = lineholder[4]
            oldutc = lineholder[5]
            status = lineholder[2]

However, I get the error

in readermain oldonline=lineholder[4] IndexError: list index out of range

After some trouble shooting it appears that the line from my constantfile is never being assigned to line. Instead it seems the line from the file portlist is being assigned to line, which only has an index of two.

My question is how to make the line that the string "address" is in assigned to line so I can parse and use it?

  • 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-06-10T14:35:18+00:00Added an answer on June 10, 2026 at 2:35 pm

    I think you are using line where you should be using lines:

    for lines in constantfile:
        if address in lines: #if the desired address is in the line
            lineholder=lines.split()
            # etc.
    

    Also, if constantfile is a file object, that iterator will be exhausted after the first pass of the outer for loop.

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

Sidebar

Related Questions

I'm trying to read in a multi line string then split it then print
I'm trying to create a function to read Morse code from one file, convert
I Im trying to read from one text file and write to another one.
I'm trying to read the last line from a text file. Each line starts
I'm trying to read a file line by line starting from a specific line
I'm trying to read a file line by line to a string type variable
I am trying to read a file line-by-line, and storing that line of data
I am trying to read file and split its line to get some context(Computer
I'm trying to read a line of text from a text file and put
I am trying to to read each line from a text file and put

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.