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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:48:19+00:00 2026-06-19T04:48:19+00:00

I have done some search but most answer is about reading a complete csv

  • 0

I have done some search but most answer is about reading a complete csv file and none of these is like the problem I’m facing.

I’m trying to read a file from net using urllib2:

request = urllib2.Request('http://.../tv.txt')
response = urllib2.urlopen(request)
lines = response.readlines()
for line in lines:
    ...

The “line” format looks like these:

"ABC", "XYZ,MNO", "KLM"
"ABC", "MN"
"ABC", "123", "10", "OPPA GANGNAM STYLE", "LADY"

As seen above, these lines are not actually CSV lines. The number of columns keeps changing.

Is there a way to split each line into a list? The desire result should be:

["ABC", "XYZ,MNO", "KLM"]
["ABC", "MN"]
["ABC", "123", "10", "OPPA GANGNAM STYLE", "LADY"]

I’ve tried using line.split(“,”) but it cannot split correctly because there is comma inside each pair of double quotes.

Please help me if you know how to. Thank you very much.

Cheers,

PHP-Python-Java-MySQL-newbie.

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

    use the csv module, it does what you need.

    yourstring= '"ABC", "XYZ,MNO", "KLM"\n"ABC", "MN"\n"ABC", "123", "10", "OPPA GANGNAM STYLE", "LADY"'
    
    import csv
    import io
    
    class MyDialect(csv.Dialect):
        strict = True
        skipinitialspace = True
        quoting = csv.QUOTE_ALL
        delimiter = ','
        quotechar = '"'
        lineterminator = '\n'
    
    
    b = io.StringIO(yourstring)
    r = csv.reader(b, MyDialect())
    
    for i in r:
        print len(i), ':',' @ '.join(i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done some search in Google but not able to find a useful
I have done some stuff in jQuery and Javascript before, but unfortunately I am
i have done some code in jquery but where i commented in this bellow
I have done stuff like this before, but I want to figure out the
First of all, I have done some search yet found no working way. Anyway,
so far I have done most view programming in code, but it really is
Good day, I've done some research looking for this answer, but haven't had much
Have done some research and found some stuff that may be helpful. I would
I have done some looking and I found this: http://www.codeproject.com/Articles/14439/The-ScrollableListBox-Custom-Control-for-ASP-NET-2 but to me it
I have done some commits and pushed them into my repository. Then I did

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.