python – How to convert binary string to normal string in Python3?

python – How to convert binary string to normal string in Python3?

Decode it.

>>> ba string.decode(ascii)
a string

To get bytes from string, encode it.

>>> a string.encode(ascii)
ba string

If the answer from falsetru didnt work you could also try:

>>> ba string.decode(utf-8)
a string

python – How to convert binary string to normal string in Python3?

Please, see oficial encode() and decode() documentation from codecs library. utf-8 is the default encoding for the functions, but there are severals standard encodings in Python 3, like latin_1 or utf_32.

Leave a Reply

Your email address will not be published. Required fields are marked *