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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:06:42+00:00 2026-06-06T03:06:42+00:00

I have a text file with text that should have been interpreted as utf-8

  • 0

I have a text file with text that should have been interpreted as utf-8 but wasn’t (it was given to me this way).
Here is an example of a typical line of the file:

\u30ed\u30f3\u30c9\u30f3\u5728\u4f4f

which should have been:

ロンドン在住

Now, I can do it manually on python by typing the following in the command line:

>>> h1 = u'\u30ed\u30f3\u30c9\u30f3\u5728\u4f4f'    
>>> print h1
ロンドン在住

which gives me what I want. Is there a way that I can do this automatically? I’ve tried doing stuff like this

>>> f = codecs.open('testfile.txt', encoding='utf-8')
>>> h = f.next()
>>> print h
\u30ed\u30f3\u30c9\u30f3\u5728\u4f4f

I’ve also tried with the ‘encode’ and ‘decode’ functions, any ideas?

Thanks!

  • 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-06T03:06:43+00:00Added an answer on June 6, 2026 at 3:06 am

    \u30ed\u30f3\u30c9\u30f3\u5728\u4f4f is not UTF8; it’s using the python unicode escape format. Use the unicode_escape codec instead:

    >>> print '\u30ed\u30f3\u30c9\u30f3\u5728\u4f4f'.decode('unicode_escape')
    ロンドン在住
    

    Here is the UTF-8 encoding of the above phrase, for comparison:

    >>> '\u30ed\u30f3\u30c9\u30f3\u5728\u4f4f'.decode('unicode_escape').encode('utf-8')
    '\xe3\x83\xad\xe3\x83\xb3\xe3\x83\x89\xe3\x83\xb3\xe5\x9c\xa8\xe4\xbd\x8f'
    

    Note that the data decoded with unicode_escape are treated as Latin-1 for anything that’s not a recognised Python escape sequence.

    Be careful however; it may be you are really looking at JSON-encoded data, which uses the same notation for specifying character escapes. Use json.loads() to decode actual JSON data; JSON strings with such escapes are delimited with " quotes and are usually part of larger structures (such as JSON lists or objects).

    • 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: STUFF UP HERE APEXED NUMBER
I have a very simple python script that should scan a text file, which
I have a text file that contains information formated in a key=value way. How
I have a text file that I want to send over the network, this
I have this text file that I read into a Java application and then
I have Text file that contains data separated with a comma , . How
I have a text file that contains the path to multiple files in the
I have a text file that I want to edit using Java. It has
I have a text file that contains a list of filenames, minus the extension,
I have a text file that looks a bit like: random text random text,

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.