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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:42:05+00:00 2026-05-11T22:42:05+00:00

I have a file in UTF-8, where some lines contain the U+2028 Line Separator

  • 0

I have a file in UTF-8, where some lines contain the U+2028 Line Separator character (http://www.fileformat.info/info/unicode/char/2028/index.htm). I don’t want it to be treated as a line break when I read lines from the file. Is there a way to exclude it from separators when I iterate over the file or use readlines()? (Besides reading the entire file into a string and then splitting by \n.) Thank you!

  • 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-11T22:42:05+00:00Added an answer on May 11, 2026 at 10:42 pm

    I can’t duplicate this behaviour in python 2.5, 2.6 or 3.0 on mac os x – U+2028 is always treated as non-endline. Could you go into more detail about where you see this error?

    That said, here is a subclass of the “file” class that might do what you want:

    #/usr/bin/python
    # -*- coding: utf-8 -*-
    class MyFile (file):
        def __init__(self, *arg, **kwarg):
            file.__init__(self, *arg, **kwarg)
            self.EOF = False
        def next(self, catchEOF = False):
            if self.EOF:
                raise StopIteration("End of file")
            try:
                nextLine= file.next(self)
            except StopIteration:
                self.EOF = True
                if not catchEOF:
                    raise
                return ""
            if nextLine.decode("utf8")[-1] == u'\u2028':
                return nextLine+self.next(catchEOF = True)
            else:
                return nextLine
    
    A = MyFile("someUnicode.txt")
    for line in A:
        print line.strip("\n").decode("utf8")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file which is mostly UTF-8, but some Windows-1252 characters have also
I am experiencing some problem on UTF-8 Encoding. I have a CSV file and
I have a Unicode file (UTF-16 FFFE little-endian BOM) which contains rows of tab-separated
I have an XML file which contains some data as given. <?xml version=1.0 encoding=UTF-8
I have an XML File <?xml version=1.0 encoding=UTF-8?> <data> <contact-information> <full-name>Peter John</full-name> <address_line_1>some place</address_line_1>
I'm working on Windows with Python 2.6.1. I have a Unicode UTF-16 text file
I have a file UTF-8 encoding in windows, and when i use it under
I have a file, which I read from test . This file is UTF-8.
I have a file which may be in ASCII or UTF-8 format. I can
I have a json file exported from phpmyadmin, it looks like this(utf-8 file): [{user_email:

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.