0

I have this string

a\xd5$\xb4S\x11w{\xf2g?z\xc2rt/\x8bN=X\x9ax\xdf\xa4\xddS0{y\x8f\x015\x16\x1cS\x87vVi\xad\x15y\x11!\x9a\x14\x93\xb3\xa0\x86\x926\xa3\x8fz\x13\xd0\xe4sW\x0c\xedI\x17

and i want to encode it to byte in python but when i run:

string.encode()

it returns me

b'a\\xd5$\\xb4S\\x11w{\\xf2g?z\\xc2rt/\\x8bN=X\\x9ax\\xdf\\xa4\\xddS0{y\\x8f\\x015\\x16\\x1cS\\x87vVi\\xad\\x15y\\x11!\\x9a\\x14\\x93\\xb3\\xa0\\x86\\x926\\xa3\\x8fz\\x13\\xd0\\xe4sW\\x0c\\xedI\\x17'

and it broke up my process because of "\", i want this:

b'a\xd5$\xb4S\x11w{\xf2g?z\xc2rt/\x8bN=X\x9ax\xdf\xa4\xddS0{y\x8f\x015\x16\x1cS\x87vVi\xad\x15y\x11!\x9a\x14\x93\xb3\xa0\x86\x926\xa3\x8fz\x13\xd0\xe4sW\x0c\xedI\x17'

how can i remove them or encode in other way?

  • 1
    If your string contains the characters "backslash x d 5", then the correctly encoded bytes version of that *is* `b'\\xd5'`. Do you want your string to be interpreted as a bytes literal and then encode it to bytes…?! – deceze Apr 25 '22 at 12:48
  • yes, i want be interpreted as a bytes literal – Arta Abbasi Apr 25 '22 at 12:52

0 Answers0