我是新的编码,并遇到一个问题,试图编码一个字符串.
- >>> import hashlib
- >>> a = hashlib.md5()
- >>> a.update('hi')
- Traceback (most recent call last):
- File "<pyshell#22>",line 1,in <module>
- a.update('hi')
- TypeError: Unicode-objects must be encoded before hashing
- >>> a.digest()
- b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
是(a)现在被认为是编码?
- import hashlib
- a = hashlib.md5()
- a.update('hi')
- a.digest()
追溯(最近呼叫最后):
文件“C:/ Users / User / Desktop / Logger / Encoding practice.py”,第3行
a.update( ‘HI’)
TypeError:Unicode散列之前必须对Unicode对象进行编码
为什么代码在shell中工作而不是脚本?
我正在使用Windows和Python 3.4
谢谢.