python string to hex with escaped hex values -


i have string "some characters \x00\x80\x34 , other characters". how can convert regular characters hex equivalent, while converting \x00 actual 00 hex value? binascii.hexlify() considers '\', 'x', '0', '0' actual characters.

later edit: string produced function. when print it, prints "\x00".

as understanding trying convert characters not hex values hex. if gave sample input string trying convert hex.

also can convert hex values using built in encoding , decoding method. should take care of trying do. following 3 lines ran in terminal of machine, , gave output expecting. attached image show you. hope helps:

astr = "some characters \x00\x80\x34 , other characters" astr.encode("hex") astr.encode("hex").decode("hex") 

here code ran in terminal.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -