-2

I have converted ascii code as printable text

>>> ascii_string = 'some text \xbb \u4500'
>>> printable_text = ascii(ascii_string)
>>> printable_text[1:-1]# remove extra quotes
'some text \\xbb \\u4500'
>>> '\xbb' in 'some text \\xbb \\u4500' 
False

Now i want to change back as original text ('some text \xbb \u4500') because i'm checking '\xbb' in ('some text \xbb \u4500') it return false value

enter image description here

user8316197
  • 45
  • 2
  • 6
  • 2
    bb is a number greater than 127 decimal so it isn't ascii – Vorsprung Aug 04 '18 at 12:39
  • @JohnColeman: oh darn, I opened Python 2 by mistake and I couldn't find it. – Matteo Italia Aug 04 '18 at 12:50
  • Hmm... Now that I'm rereading this might not be quite a duplicate, given the extra quotes to be eliminated. `ast.literal_eval` would handle that though. – ShadowRanger Aug 04 '18 at 13:12
  • @ShadowRanger It is either unclear or a duplicate. Either way, closing it seems warranted. – John Coleman Aug 04 '18 at 13:24
  • @ShadowRanger thanks to respond, yes i removed extra quotes, after i checking '\xbb' in ('some text \\xbb \\u4500') it return false value, i need to check '\xbb' is present that text ('some text \\xbb \\u4500') – user8316197 Aug 04 '18 at 13:48

1 Answers1

0

Simply declare the string as raw (with r in front of it) and it will print all its characters as is:

>>> s = r'some text \xbb'
>>> print s
'some text \xbb'
0xInfection
  • 2,676
  • 1
  • 19
  • 34