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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:33:13+00:00 2026-06-15T04:33:13+00:00

results = open(filename, ‘r’) line = results.readline() while line != ”: # results for

  • 0
results = open(filename, 'r')


   line = results.readline()
   while line != '':
    # results for a single draw
    star = line[line.rfind('\t') :]
    stars.append(star)
    line =results.readline()
'''

while line != '':


   main = [line[:line.rfind('\t')]]
   mains.append(main)
   line =results.readline()
return (mains)

I am using the above script to read from a text file in the format 1,2,3,4,5 tab 9,10new line 6,7,8,9,10 tab 11,12 and am trying to get back [[1,2,3,4,5],[6,7,8,9,10]]The above script gives me [[‘1,2,3,4,5’],[‘6,7,8,9,10’]] -the parentheses prevent me using the data. Forgive me for once again being stupid, but how do I get the list format back from the text file? I did try to read other posts, but haven’t been able to apply the suggestions – too new to this
Many thanks for any help

  • 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-15T04:33:15+00:00Added an answer on June 15, 2026 at 4:33 am

    Try:

    # say your data is in file named 'testfile'
    $ cat testfile 
    1,2,3,4,5   9,10
    6,7,8,9,10  11,12
    
    # the actual code
    datafile = [line.strip().split('\t')[0].split(',') for line in open('testfile')]   
    result = []
    for l in datafile:
        result.append([int(string) for string in l])
    # test the results
    print(result)
    [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
    

    EDIT:
    For getting both parts of each line, try:

    datafile = [line.strip() for line in open('testfile')]
    datafile = [line.split('\t') for line in datafile if line]
    datalist = list(zip(*datafile))
    result = []
    for index in datalist:
        for i in index:
            result.append([int(string) for string in i.split(',')])
    # you can access the result list by indexing:
    print(result[:2], result[2:])
    # or assign to new lists:
    firstlist, secondlist = result[:2], result[2:]
    print(firstlist, secondlist)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python, calling e.g. temp = open(filename,'r').readlines() results in a list in which each
I'm looking to open search results at http://iswcnet.cisac.org/ with the search parameters POSTed from
So, basically, I've got a search results screen with an Open button for each
Hii I am getting the following error in Biopython: 'return' outside function (filename.. line
I have two cases. The preliminary code: open Microsoft.Office.Interop.Excel let xl = ApplicationClass() xl.Workbooks.OpenText(fileName...)
I have the following loop: for fileName in fileList: f = open(fileName) txt =
Going to http://127.0.0.1:8300/projects/cprshelp/edit_file/?filename=manage.py results in a 404 error urls.py (r'^projects/(?P<project_name>[\w ,-<>]+)/', include('projects.urls')), projects/urls.py (r'edit_file/$',
When I tried the console programming, I received unexpected result. open System let printSomeMessage
Results Lock: 85.3 microseconds Monitor.TryEnter: 11.0 microseconds Isn't the lock expanded into the same
Results are in clean files. I want to get them to latex-table format with

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.