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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:17:34+00:00 2026-05-10T16:17:34+00:00

In a text file, there is a string I don’t like this. However, when

  • 0

In a text file, there is a string ‘I don’t like this’.

However, when I read it into a string, it becomes ‘I don\xe2\x80\x98t like this’. I understand that \u2018 is the unicode representation of ”’. I use

f1 = open (file1, 'r') text = f1.read() 

command to do the reading.

Now, is it possible to read the string in such a way that when it is read into the string, it is ‘I don’t like this’, instead of ‘I don\xe2\x80\x98t like this like this’?

Second edit: I have seen some people use mapping to solve this problem, but really, is there no built-in conversion that does this kind of ANSI to unicode ( and vice versa) conversion?

  • 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. 2026-05-10T16:17:34+00:00Added an answer on May 10, 2026 at 4:17 pm

    Ref: http://docs.python.org/howto/unicode

    Reading Unicode from a file is therefore simple:

    import codecs with codecs.open('unicode.rst', encoding='utf-8') as f:     for line in f:         print repr(line) 

    It’s also possible to open files in update mode, allowing both reading and writing:

    with codecs.open('test', encoding='utf-8', mode='w+') as f:     f.write(u'\u4500 blah blah blah\n')     f.seek(0)     print repr(f.readline()[:1]) 

    EDIT: I’m assuming that your intended goal is just to be able to read the file properly into a string in Python. If you’re trying to convert to an ASCII string from Unicode, then there’s really no direct way to do so, since the Unicode characters won’t necessarily exist in ASCII.

    If you’re trying to convert to an ASCII string, try one of the following:

    1. Replace the specific unicode chars with ASCII equivalents, if you are only looking to handle a few special cases such as this particular example

    2. Use the unicodedata module’s normalize() and the string.encode() method to convert as best you can to the next closest ASCII equivalent (Ref https://web.archive.org/web/20090228203858/http://techxplorer.com/2006/07/18/converting-unicode-to-ascii-using-python):

      >>> teststr u'I don\xe2\x80\x98t like this' >>> unicodedata.normalize('NFKD', teststr).encode('ascii', 'ignore') 'I donat like this' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks like this: value1 value2 value3 There are
I'm trying to read just the integers from a text file structured like this....
I'm trying to read in a 150mb text file into a Rich Text box.
I'm trying to read the contents of a text file into the attributes of
I have a text file apple banana Now you watch closely there is blank
Is there any way to write to a text file in Flex 4.6? Its
Supposed a text file named name.txt . there are some contents as the following
I have java source code in a text file. There has to be entered
According to the text in avcodec.h file, there are some decoders may support multiple
I have text file with something like first line line nr 2 line three

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.