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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:34:14+00:00 2026-06-05T01:34:14+00:00

I just started python, any suggestions would be greatly appreciated. I’m reading a table

  • 0

I just started python, any suggestions would be greatly appreciated. I’m reading a table generated by another program and pulling out 2 numbers from each line, I’ll call them a and b. (they are saved as flux and observed in my program) I need to take these two numbers from each line and format them like this-

(a,b),(a,b),(a,b) ect. 

Each consecutive parenthesis is from the consecutive line, first a,b is from line 1, second a,b is from line 2, etc. I need to read the entire table however, the table length will vary.

This is what I have so far. It can read the table and pull out the numbers I need, however, I don’t know how to put the numbers into the proper format. I want to say something recursive would be most efficient but I’m unsure of how to do that. Thank you in advance.

#!/usr/bin/python

file = open("test_m.rdb")

 while 1:
    line = file.readline()
    i = line.split()
    flux = i[2]
    observed = i[4]
    if not line:
        break
  • 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-05T01:34:16+00:00Added an answer on June 5, 2026 at 1:34 am
    with open("test_m.rdb") as inf:
        results = [(i[2],i[4]) for i in (line.split() for line in inf)]
    
    result_string = ",".join(str(res) for res in results)
    

    or a more general formatter:

    result_string = ", ".join("('{2}', '{4}')".format(*res) for res in results)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So ive just started learning python on WAMP, ive got the results of a
I've just started learning about Gimp scripting using Python, and was wondering, how do
So I'm really new to programming, I just started learning Python yesterday and I'm
This should be easy but I have just started toying with matplotlib and python.
I have just started learning Lucene and would like to use it for indexing
So I just started learning Python and just now set up my Notepad++ to
I've just started learning Python and I'm slowly getting the hang of it, but
I am just getting started with Python/Jython and the SAX parser ( xml.sax ).
I'm very new to python (just started yesterday), and I'm trying to create permutations
I just started to use the object oriented programming in Python. I wander if

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.