Is there a python equivalent to echo -e?
In other words, is there a built-in function to convert r"\x50\x79\x74\x68\x6f\x6e" to "Python" in Python?
Edit I added the 'r' prefix, to make sure everyone understands that I do not want the python interpreter to convert this. Rather, I want to convert that 24-character string to a 6-character one.
The correct way to do this, which I just found is
>>> a = r"\x50\x79\x74\x68\x6f\x6e"
>>> print a
\x50\x79\x74\x68\x6f\x6e
>>> a.decode('string_escape')
'Python'
Make sure you are escaping the backslashes (or using the raw 'r' prefix) when testing this!
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With