2

How can I convert

(type["str"])" b' ' "

to

(type["bytes"],len =16)b' ' 

in python3

For example: I want to convert

"b'\xf5\xd9\xfc\x8b\x05W\xa5"\xcad\xb6\x15\xc5\xba?\xfe'" 

to

b'\xf5\xd9\xfc\x8b\x05W\xa5"\xcad\xb6\x15\xc5\xba?\xfe' 

How can I do?

詹哲瑜
  • 21
  • 2
  • This question may have already been answered [here](https://stackoverflow.com/questions/35310695/convert-byte-string-to-bytes-or-bytearray) – jonroethke Jul 15 '18 at 17:31
  • Have a look at [this](https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3) SO question. – Jeroen Heier Jul 15 '18 at 17:33
  • I have tried it. He will return my array of one word. This needs to be a byte itself – 詹哲瑜 Jul 15 '18 at 17:37
  • Possible duplicate of [Convert byte string to bytes or bytearray](https://stackoverflow.com/questions/35310695/convert-byte-string-to-bytes-or-bytearray) – dns_nx Jul 15 '18 at 17:41
  • My list has no way to convert to utf8 because he has been encrypted He will return that I can't convert utf8 – 詹哲瑜 Jul 15 '18 at 17:42
  • Possible duplicate of [Best way to convert string to bytes in Python 3?](https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3) – Taslim Oseni Jul 15 '18 at 17:48
  • 1
    if your input string is the representation of a byte string (with leading `b` and string quotes), you can use the `eval` function – Aemyl Jul 15 '18 at 18:25
  • 1
    Oh, that's ok, thank you Aemyl. – 詹哲瑜 Jul 16 '18 at 03:28

0 Answers0