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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:18:24+00:00 2026-05-29T20:18:24+00:00

I usually use the following Python code to read lines from a file :

  • 0

I usually use the following Python code to read lines from a file :

f = open('./my.csv', 'r')
for line in f:
    print line

But how about if the file is line delimited by “\0” (not “\n”) ? Is there a Python module that could handle this ?

Thanks for any advice.

  • 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-29T20:18:27+00:00Added an answer on May 29, 2026 at 8:18 pm

    If your file is small enough that you can read it all into memory you can use split:

    for line in f.read().split('\0'):
        print line
    

    Otherwise you might want to try this recipe from the discussion about this feature request:

    def fileLineIter(inputFile,
                     inputNewline="\n",
                     outputNewline=None,
                     readSize=8192):
       """Like the normal file iter but you can set what string indicates newline.
       
       The newline string can be arbitrarily long; it need not be restricted to a
       single character. You can also set the read size and control whether or not
       the newline string is left on the end of the iterated lines.  Setting
       newline to '\0' is particularly good for use with an input file created with
       something like "os.popen('find -print0')".
       """
       if outputNewline is None: outputNewline = inputNewline
       partialLine = ''
       while True:
           charsJustRead = inputFile.read(readSize)
           if not charsJustRead: break
           partialLine += charsJustRead
           lines = partialLine.split(inputNewline)
           partialLine = lines.pop()
           for line in lines: yield line + outputNewline
       if partialLine: yield partialLine
    

    I also noticed your file has a "csv" extension. There is a CSV module built into Python (import csv). There is an attribute called Dialect.lineterminator however it is currently not implemented in the reader:

    Dialect.lineterminator

    The string used to terminate lines produced by the writer. It defaults to ‘\r\n’.

    Note The reader is hard-coded to recognise either ‘\r’ or ‘\n’ as end-of-line, and ignores lineterminator. This behavior may change in the future.

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

Sidebar

Related Questions

I usually use this line to import file from out of the current folder
I usually use the following idiom when working with a Python dictionary: try: val
In our code we usually use the following pattern: Connection conn; try{ conn =
I usually use the following pipeline to grep for a particular search string and
I usually use pointers in the following manner char *ptr = malloc( sizeof(char) *
I usually use IIS in conjunction with the OutSystems development platform, which does code-generation
I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but
I usually use sql parameters with queries, but in this case I need to
Usually, I use SELECT * FROM tableName WHERE fieldName LIKE '%string%' to find every
When I write C/C++ code for Windows platform, I usually use Windows APIs as

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.