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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:33:53+00:00 2026-05-29T21:33:53+00:00

I have a v. large text document (no file extension) that has information about

  • 0

I have a v. large text document (no file extension) that has information about a different file on every line in the following format:

VariableOne|VariableTwo|VaraibleThree

The pipe separates the different variables.
However, within some ‘VaraibleTwo’s there may also be pipes.

I need to extract that information from the text document so that I can manipulate the information. For example:

Name = VariableOne From The Text Document
Middle Name(s) = VariableTwo From The Text Document
Last Name = VariableThree From The Text Document

This needs to be done in Python 3 with six variables all together and only the second variable containing pipes.

Thanks for any help you can give!

  • 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-05-29T21:33:54+00:00Added an answer on May 29, 2026 at 9:33 pm

    How about:

    >>> s = 'a|b|more b|yet more b|c|d|e|f'
    >>> a, *b, c, d, e, f = s.split('|')
    >>> b = '|'.join(b)
    >>> 
    >>> a,b,c,d,e,f
    ('a', 'b|more b|yet more b', 'c', 'd', 'e', 'f')
    

    where you could replace the explicit naming by slicing the split result, which might be a little more general. As for reading the file, the usual pattern is

    with open('somefile') as fp:
        for line in fp:
            a, *b, c, d, e, f = line.strip().split('|')
            b = '|'.join(b)
            # do something
    

    which doesn’t read the entire file into memory at once, which is handy for large files.

    UPDATE: if you have to loop over all the lines, but only process one, then you could use

    with open('somefile') as fp:
        for i, line in enumerate(fp):
            if i == some_number:
                a, *b, c, d, e, f = line.strip().split('|')
                b = '|'.join(b)
    

    On the other hand, if there’s only one line you need to extract and process, you can use the linecache module:

    def proc(filename, lineno):
        line = linecache.getline(filename, lineno)
        a, *b, c, d, e, f = line.strip().split('|')
        b = '|'.join(b)
        # do something
    

    Although to be honest, I think I prefer Karl Knechtel’s two-argument split approach because it’s more general.

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

Sidebar

Related Questions

I have a rather large text file that has a bunch of missing newlines,
I have a large Ruby on Rails form that has the following partial view
I have a large text file I am reading from and I need to
I have a a large text file (over 70mb) and need to count the
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have a large body of text which has several sentences wrapped in yada
I have a very large text file and I need to gather data from
Background Info: I have a large body of text that I regularly encapsulate in
I have a large PDF file that is a floor map for a building.
I currently have a large .sqlite data store of long string text. It's about

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.