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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:55:55+00:00 2026-06-12T20:55:55+00:00

At some point our python script receives string like that: In [1]: ab =

  • 0

At some point our python script receives string like that:

In [1]: ab = 'asd\xeffe\ctive'

In [2]: print ab
asd�fe\ctve \ \\ \\\k\\\

Data is damaged we need escape \x to be properly interpreted as \x but \c has not special meaning in string thus must be intact.

So far the closest solution I found is do something like:

In [1]: ab = 'asd\xeffe\ctve \\ \\\\ \\\\\\k\\\\\\'

In [2]: print ab.encode('string-escape').replace('\\\\', '\\').replace("\\'", "'")

asd\xeffe\ctve \ \\ \\\k\\\

Output taken from IPython, I assumed that ab is a string not unicode string (in the later case we would have to do something like that:

def escape_string(s):
    if isinstance(s, str):
        s = s.encode('string-escape').replace('\\\\', '\\').replace("\\'", "'")
    elif isinstance(s, unicode):
        s = s.encode('unicode-escape').replace('\\\\', '\\').replace("\\'", "'")
    return s
  • 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-12T20:55:56+00:00Added an answer on June 12, 2026 at 8:55 pm

    '\\' is the same as '\x5c'. It is just two different ways to write the backslash character as a Python string literal.

    These literal strings: r'\c', '\\c', '\x5cc', '\x5c\x63' are identical str objects in memory.

    '\xef' is a single byte (239 as an integer), but r'\xef' (same as '\\xef') is a 4-byte string: '\x5c\x78\x65\x66'.

    If s[0] returns '\xef' then it is what s object actually contains. If it is wrong then fix the source of the data.


    Note: string-escape also escapes \n and the like:

    >>> print u'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''.encode('unicode-escape')
    \xef\\c\\\u2603"'\u2603\u2603"'\n\xa0
    >>> print b'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''.encode('string-escape')
    \xef\\c\\\\N{SNOWMAN}"\'\xe2\x98\x83\\u2603"\'\n\xa0
    

    backslashreplace is used only on characters that cause UnicodeEncodeError:

    >>> print u'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''
    ï\c\☃"'☃☃"'
    
    >>> print b'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''
    �\c\\N{SNOWMAN}"'☃\u2603"'
    �
    >>> print u'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''.encode('ascii', 'backslashreplace')
    \xef\c\\u2603"'\u2603\u2603"'
    \xa0
    >>> print b'''\xef\c\\\N{SNOWMAN}"'\
    ... ☃\u2603\"\'\n\xa0'''.decode('latin1').encode('ascii', 'backslashreplace')
    \xef\c\\N{SNOWMAN}"'\xe2\x98\x83\u2603"'
    \xa0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a memory overwrite problem. At some point, during the course of our
At some point Find All References feature got broken for a single solution that
I have written some Python scripts in Eclipse where at some point I have
I have a Python script that we're using to parse CSV files with user-entered
At some point in our lives we're put in the situation to learn a
We are making some kNN and SVD implementations in Python. Others picked Java. Our
At some point our WebLogic's Portal web project in Workshop stopped generating the WEB-INF/classes/_pageflow
I remember that at some point, I saw a programming challenge where people were
We have a question we ask at our office during interviews that goes like
We have a situation in our product where for a long time some data

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.