首页 Python python2 str object has no attribute decode

python2 str object has no attribute decode

0102030405060708.decode(hex)上述代码,报错:str object has no attribute decode查找原因:https://stackoverflow.com/questions/29030725/str-object-has-no-attribute-decodeYou cannot decode string objects; they arealreadydecoded. Youll have to u

<div class=”cnblogs_code”>

.decode()

上述代码,报错:

‘str’ object has no attribute ‘decode’

查找原因:

https://stackoverflow.com/questions/29030725/str-object-has-no-attribute-decode

You cannot decode string objects; they arealreadydecoded. You’ll have to use a different method.

You can use thecodecs.decode()functionto applyhexas a codec:

>>>>

This applies aBinary transformcodec; it is the equivalent of using thebase64.b16decode()function,with the input string converted to uppercase:

>>>>

You can also use thebinascii.unhexlify()functionto ‘decode’ a sequence of hex digits to bytes:

>>>>

Either way,you’ll get abytesobject.

使用第二种方式解决了:

>>> >>> base64.b16decode()

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/kaifa/python/20200729/7246.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部