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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer In your Hudson job configuration you can specify ant arguments… May 11, 2026 at 9:42 am
  • added an answer If all you want is the UNIX command line tools… May 11, 2026 at 9:42 am
  • added an answer apropos yeilds the command locale 10.4 and later though Edit:… May 11, 2026 at 9:42 am

Related Questions

In a text file, there is a string I don't like this. However, when
Is there a way to include an entire text file as a string in
Is there any way to determine if a text file is currently open in
If I have a list of data in a text file seperated by a
A lot of programs log things into a text file in a format something
What's the best way to return a random line in a text file using
I want to execute some mysql statements that are stored in a text file
I'm reading in a large text file with 1.4 million lines that is 24
I'm trying to read the contents of a text file, in this case a
Parsing a text file in vb.net and need to locate the latitude and longitude

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.