0

i'm trying to convert ASCII values in string to normal characters, but whatever i'll try to do, i'll get output like

this\032is\032my\032\output\000

and I need

this is my output

Thanks for your help!

2
  • @RyanHaining Same as my output Commented Apr 15, 2018 at 18:02
  • In case you want to ask more questions on Stack Overflow: what is your input? and what is your code? Without these two, we cannot tell what you did wrong. Commented Apr 15, 2018 at 18:37

2 Answers 2

1

I solved it with

import re
def replace(match):
    return chr(int(match.group(1)))
aux = str(element.text)
regex = re.compile(r"\\(\d{1,3})")
new = regex.sub(replace, aux)

where element.text is string i need to convert

Sign up to request clarification or add additional context in comments.

Comments

0

\032 is octal for the decimal number 26, so it is not in fact a space character, if you use a hex value with the correct number, you should get what you want. 0x20 == 32 below

>>> s = 'this\x20is\x20my\x20\output\00'
>>> print(s)
this is my \output

4 Comments

I know, but I have to do it with decimal number
@Brykyz why? Are you getting numbers from user input that you are trying to convert?
Because it's school assignment
this is a very strange assignment if the strings actually have \032 in them since that already means something to python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.