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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:51:54+00:00 2026-06-17T18:51:54+00:00

I have a file which looks like the following: @ junk … @ junk

  • 0

I have a file which looks like the following:

@ junk
...
@ junk
    1.0  -100.102487081243
    1.1  -100.102497023421
    ...   ...
    3.0  -100.102473082342
&
@ junk
...

I am interested only in the two columns of numbers given between the @ and & characters. These characters may appear anywhere else in the file but never inside the number block.

I want to create two lists, one with the first column and one with the second column.

List1 = [1.0, 1.1,..., 3.0]
List2 = [-100.102487081243, -100.102497023421,..., -100.102473082342]

I’ve been using shell scripting to prep these files for a simpler Python script which makes lists, however, I’m trying to migrate these processes over to Python for a more consistent application. Any ideas? I have limited experience with Python and file handling.

Edit: I should mention, this number block appears in two places in the file. Both number blocks are identical.

Edit2: A general function would be most satisfactory for this as I will put it into a custom library.

Current Efforts

I currently use a shell script to trim out everything but the number block into two separate columns. From there it is trivial for me to use the following function

def ReadLL(infile):
    List = open(infile).read().splitlines()
    intL = [int(i) for i in List]
    return intL

by calling it from my main

import sys
import eLIBc
infile = sys.argv[1]
sList = eLIBc.ReadLL(infile)

The problem is knowing how to extract the number block from the original file with Python rather than using shell scripting.

  • 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-17T18:51:56+00:00Added an answer on June 17, 2026 at 6:51 pm

    You want to loop over the file itself, and set a flag for when you find the first line without a @ character, after which you can start collecting numbers. Break off reading when you find the & character on a line.

    def readll(infile):    
        with open(infile) as data:
            floatlist1, floatlist2 = [], []
            reading = False
    
            for line in data:
                if not reading:
                    if '@' not in line:
                        reading = True
                    else:
                        continue
    
                if '&' in line:
                    return floatlist1, floatlist2
    
                numbers = map(float, line.split())
                floatlist1.append(numbers[0])
                floatlist2.append(numbers[1])
    

    So the above:

    • sets ‘reading’ to False, and only when a line without '@' is found, is that set to True.
    • when ‘reading’ is True:
      • returns the data read if the line contains &
      • otherwise it’s assumed the line contains two float values separated by whitespace, which are added to their respective lists

    By returning, the function ends, with the file closed automatically. Only the first block is read, the rest of the file is simply ignored.

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

Sidebar

Related Questions

I currently have a make file, part of which looks like the following. ####################################################################
I have an XML file which looks like the following: <a> ...... <b> <c>
I have a JSON file which looks like the following: {"posts":[{"Latitude":"53.38246685","lontitude":"-6.41501535"}, {"Latitude":"53.4062787","lontitude":"-6.3767205"}]} and I
I have a 20 gb file which looks like the following: Read name, Start
I want to read xml file which looks like the following ... I have
I have an .ini file which looks like: password = password123 username = username123
I have a tab delimited file which looks like this: CHROM <TAB> POS <TAB>
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have a text file, which looks like this: node13 state = free np

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.