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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:44:16+00:00 2026-06-11T18:44:16+00:00

I am trying to parse a pseudo-CSV file with the python CSV reader, and

  • 0

I am trying to parse a “pseudo-CSV” file with the python CSV reader, and am having some doubts about how to add some extra logic. The reason I call it a “pseudo-CSV” file is because some of the lines in the input file will have text (30-40 chars) before the actual CSV data starts. I am trying to figure out the best way to remove this text.

Currently, I have found 3 options for removing said text:

  1. From Python, call grep and sed and pipe the output to a temp file which can then be fed to the csv reader
    (Ugh, I would like to avoid this option)

  2. Create a CSV dialect to remove the unwanted text
    (This option just feels wrong)

  3. Extend the File object, implementing the next() function to remove the unwanted text as necessary.

I have no control over how the input file is generated, so its not an option to modify the generation.

Here is the related code I had when I realized the problem with the input file.

with open('myFile', 'r') as csvfile:
theReader = csv.reader(csvfile)
for row in theReader:
     # my logic here

If I go with option 3 above, the solution is quite straight-forward, but
then I wont be able to incorporate the with open() syntax.

So, here is my question (2 actually): Is option 3 the best way to solve this
problem? If so, how can I incorporate it with the with open() syntax?

Edit: Forgot to mention that Im using Python 2.7 on Linux.

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

    csv.reader accepts an arbitrary iterable besides files:

    with open('myFile', 'rb') as csvfile:
         reader = csv.reader(filter_line(line) for line in csvfile)
         for row in reader:
             # my logic here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a CSV file in C#. Split on commas (,). I
I'm trying to parse some data in a fixed format text file where each
I am trying parse out some text that is in an html file. The
Trying to parse a csv file that has all the data wrapped in double
I am trying to parse a csv file and in the process have come
I’m trying to parse text from a file that comes in a pseudo XML
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
Trying to parse a CSV file, but still getting the error message Unquoted fields
Trying to parse some spam injection out of a mysql export file, and for
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>

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.