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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:05+00:00 2026-05-26T09:33:05+00:00

I am dealing with a CSV file similar to this one foo; val1; position1

  • 0

I am dealing with a CSV file similar to this one

foo; val1; position1
bar; name1; address1; phone_nbr1
bar; name2; address2; phone_nbr2
foo; val2; position2
bar; name3; address3; phone_nbr3
bar; name4; address4; phone_nbr4
bar; name5; address5; phone_nbr5
bar; name6; address6; phone_nbr6
foo; val3; position3

Needless to say, I cannot modify the CSV.

Instances displayed in foo lines are different from the ones with bar lines (notice they don’t even have the same number of fields)

I need simply reading this data, no need to write it.

My first idea was to separate the file into two temporary files and then read each one separately with a csv.DictReader, however I really don’t like this approach.

Is there a simpler way to do this? I would like to avoid if possible having to write files to disk.

For the record, I’m using Python2.7 on a Solaris 10 machine.

  • 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-26T09:33:06+00:00Added an answer on May 26, 2026 at 9:33 am

    You could collect the records from a csv.reader in two different lists, depending on their length (or whatever criterion you use to distinguish the two streams):

    list1 = []
    list2 = []
    with open("input.csv", "rb") as f:
        for record in csv.reader(f, delimiter=";"):
            if len(record) == 3:
                list1.append(record)
            else:
                list2.append(record)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am dealing with a csv file that has some customer information (email, name,
So I'm dealing with a csv file that has missing values. What I want
I am reading in a csv file and dealing with each line as a
I have this .csv file: ID,GRADES,GPA,Teacher,State 3,C,2,Teacher3,MA 1,A,4,Teacher1,California And what I want to do
I have csv file with a line that looks something like this: ,,,,,,,,,, That's
Possible Duplicate: Dealing with commas in a CSV file We are exporting a bulk
When dealing with a single file, I'm used to: /blah do some work n
I am using scala 2.7.7, and wanted to parse CSV file and store the
I have an application where we're having our clients upload a csv file to
I have been writing an implementation for reading a .csv data file into C#

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.