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 8880919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:14:50+00:00 2026-06-14T20:14:50+00:00

I am having issues reading a text file into Python, i am using a

  • 0

I am having issues reading a text file into Python, i am using a loop and it keeps stopping before the end of the text file as well as skipping the first line of the file, i’m sorting it into a dictionary as i read each line.My code is:

for x in file.readline():
    s=file.readline().rstrip()
    s=s.split(': ')
    if s[0]=='RootObject':
        Root=s[1]
    if s[0]=='Object':
        data[s[1]]={}
        Ob=s[1]
    elif s[0]=='Satellites':
        data[Ob][s[0]]=s[1]
    elif s[0]=='Orbital Radius':
        data[Ob][s[0]]=float(s[1])
    elif s[0]=='Period':
        data[Ob][s[0]]=float(s[1])
    elif s[0]=='Radius':
        data[Ob][s[0]]=float(s[1])
  • 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-14T20:14:51+00:00Added an answer on June 14, 2026 at 8:14 pm

    It doesn’t make sense to iterate over file.readline() like that. You should iterate over the lines instead like this:

    with open('/your/file.txt') as f:
      for line in f:
        s = line.rstrip().split(': ')
        # etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm having an issue reading a text file into my program. Here is
I've been having some issues reading an XML file in my 'res' folder and
For some reason, Python seems to be having issues with BOM when reading unicode
I'm having memory issues while reading video frames from an existing video chosen from
I am having following issue with reading binary file in C. I have read
Am having issues with printing different sized PDF's using GhostScript (V9.05). The PDF in
Im having issues vertically positioning text inside of a text input field in Firefox.
I am having issues passing a dynamic parameter to a JavaScript function using innerHTML.
I am having issues reading data from a socket. Supposedly, there is a server
I am using phonegap file reading functionality, once i read the content and i

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.