I want to read all strings from Python file. Example file (/tmp/s.py):
s = '{\x7f5 x'
Now I try to read the string from my script:
import re
find_str = re.compile(r"'(.+?)'")
for line in open('/tmp/s.py', 'r'):
all_strings = find_str.findall(line)
print(all_strings) # outputs ['{\\x7f5 x']
But I want the string (in this case the byte that is in escaped hex representation) not to be escaped. I want to treat the data was it is in my /tmp/s.py file and to get a string with a interpreted \x7f byte, instead of the literal \x7f, which is right now represented as \\x7f.
How can I do this?