What's the correct way to convert bytes to a hex string in Python 3?

前端 未结 9 2084
一生所求
一生所求 2020-11-22 14:11

What\'s the correct way to convert bytes to a hex string in Python 3?

I see claims of a bytes.hex method, bytes.decode codecs, and have tri

9条回答
  •  长情又很酷
    2020-11-22 14:34

    import codecs
    codecs.getencoder('hex_codec')(b'foo')[0]
    

    works in Python 3.3 (so "hex_codec" instead of "hex").

提交回复
热议问题