Since your input is in Python’s syntax, for some reason (*), the thing to do
here is just call
eval:
>>> r"b'x12x12'""b'\x12\x12'">>> eval(r"b'x12x12'")'x12x12'
Be careful, though, as this may be a security problem.
evalwill run any
pre, so you may need to sanitize the input. In your case its simple - just
check that the thing you’re
eval-ing is indeed a string in the format you
expect. If security isn’t an issue here, just don’t bother.
Redarding your EDIT : Still,
evalis the simplest approach here (after
adding the
b''if it’s not there). You could also, of course, do this
manually by converting each
xXXto its real value.
(*) Why, really? This seems like a strange choice for a data representation
format



