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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:26:38+00:00 2026-06-08T02:26:38+00:00

I have searched high and low for a resolution to this situation, and tested

  • 0

I have searched high and low for a resolution to this situation, and tested a few different methods, but I haven’t had any luck thus far. Basically, I have a file with data in the following format that I need to convert into a CSV:

(previously known as CyberWay Pte Ltd)
0 2019
01.com
0 1975
1 TRAVEL.COM
0 228
1&1 Internet
97 606
1&1 Internet AG
0 1347
1-800-HOSTING
0 8
1Velocity
0 28
1st Class Internet Solutions
0 375
2iC Systems
0 192

I’ve tried using re.sub and replacing the whitespace between the numbers on every other line with a comma, but haven’t had any success so far. I admit that I normally parse from CSVs, so raw text has been a bit of a challenge for me. I would need to maintain the string formats that are above each respective set of numbers.

I’d prefer the CSV to be formatted as such:

foo bar
0,8
foo bar
0,9
foo bar
0,10
foo bar
0,11

There’s about 50,000 entries, so manually editing this would take an obscene amount of time.

If anyone has any suggestions, I’d be most grateful.

Thank you very much.

  • 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-08T02:26:39+00:00Added an answer on June 8, 2026 at 2:26 am

    If I have correctly understood your requirement, you need a strip() on all lines and a split based on whitespace on even lines (lines starting from 1):

    import re
    
    fp = open("csv.txt", "r")
    while True:
        line = fp.readline()
        if '' == line:
                break
        line    = line.strip()
        fields  = re.split("\s+", fp.readline().strip())
        print "\"%s\",%s,%s" % ( line, fields[0], fields[1] )
    fp.close()
    

    The output is a CSV (you might need to escape quotes if they occur in your input):

    "Content of odd line",Number1,Number2
    

    I do not understand the ‘foo,bar’ you place as header on your example’s odd lines, though.

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

Sidebar

Related Questions

I have searched high and low, but I can't figure this one out. I
I have searched high and low and tried multiple different solutions to this and
I have searched high and low but can't get this to work. TextView topic
I have searched high and low for this solution. Any insights will be highly
I have searched high and low for documentation on this, but I just cannot
I have searched high and low for documentation on how to use this feature.
I haven't searched real hard recently but in the past I have searched high
I have searched high and low to no avail, and this is last step
I have searched high and low, but have found very little to achieve my
I have searched high and low and tried various patterns but it seems 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.