这是我的代码,
if __name__ == "__main__":
key = "0123456789abcdef0123456789abcdef".decode('hex') /this line is having error
plain_1 = "1weqweqd"
plain_2 = "23444444"
plain_3 = "dddd2225"
print(plain_1)
print(plain_2)
print(plain_3)
cipher = Present(key)
输出
AttributeError: 'str' object has no attribute 'decode'
最佳答案
这是因为你试图解码一个字符串。 bytes
类型可以解码,str
类型不能解码。你应该编码 (key.encode()
) this (or use b"foo"
) before, to convert the string to a bytes
object .
>>> foo = "adarcfdzer"
>>> type(foo)
<class 'str'>
>>> foo = foo.encode()
>>> type(foo)
<class 'bytes'>
>>> foo = foo.decode()
>>> type(foo)
<class 'str'>
关于python - 属性错误 : 'str' object has no attribute 'decode' Having this error on the second line of my code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51478951/