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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:06:49+00:00 2026-05-15T07:06:49+00:00

I have a Python script that pulls in data from many sources (databases, files,

  • 0

I have a Python script that pulls in data from many sources (databases, files, etc.). Supposedly, all the strings are unicode, but what I end up getting is any variation on the following theme (as returned by repr()):

u'D\\xc3\\xa9cor'
u'D\xc3\xa9cor'
'D\\xc3\\xa9cor'
'D\xc3\xa9cor'

Is there a reliable way to take any four of the above strings and return the proper unicode string?

u'D\xe9cor' # --> Décor

The only way I can think of right now uses eval(), replace(), and a deep, burning shame that will never wash away.

  • 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-15T07:06:50+00:00Added an answer on May 15, 2026 at 7:06 am

    That’s just UTF-8 data. Use .decode to convert it into unicode.

    >>> 'D\xc3\xa9cor'.decode('utf-8')
    u'D\xe9cor'
    

    You can perform an additional string-escape decode for the 'D\\xc3\\xa9cor' case.

    >>> 'D\xc3\xa9cor'.decode('string-escape').decode('utf-8')
    u'D\xe9cor'
    >>> 'D\\xc3\\xa9cor'.decode('string-escape').decode('utf-8')
    u'D\xe9cor'
    >>> u'D\\xc3\\xa9cor'.decode('string-escape').decode('utf-8')
    u'D\xe9cor'
    

    To handle the 2nd case as well, you need to detect if the input is unicode, and convert it into a str first.

    >>> def conv(s):
    ...   if isinstance(s, unicode):
    ...     s = s.encode('iso-8859-1')
    ...   return s.decode('string-escape').decode('utf-8')
    ... 
    >>> map(conv, [u'D\\xc3\\xa9cor', u'D\xc3\xa9cor', 'D\\xc3\\xa9cor', 'D\xc3\xa9cor'])
    [u'D\xe9cor', u'D\xe9cor', u'D\xe9cor', u'D\xe9cor']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python Script that generate a CSV (data parsed from a website).
I have a little python script that pulls emails from a POP mail address
I am currently working on a python script that pulls data from a table
I have a python script that runs a program, which generates few .exe files
I have a Python script that reads a file (typically from optical media) marking
I have af python script that download attchments from a POP3 mailbox. But I
I have a python script that calls a USB-based data-acquisition C# dotnet executable. The
I have a python script that calls a USB-based data-acquisition C# dotnet executable. The
I have python script that converts data.xml to html using stylesheet.xsl. And i have
I have a Python script that takes in '.html' files removes stop words and

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.