Form sha1.hexdigest to sha1.digest

"Martin v. Löwis" martin at v.loewis.de
Sun Apr 6 17:50:01 EDT 2008


>>> Or hexdigest_string.decode('hex')
>> I would advise against this, as it's incompatible with Python 3.
> 
> I didn't know that, you actually made me look it up in the Python 3
> FAQ. And yes, the difference is that decode will return bytes type
> instead of a string.

No. The decode method on string objects is removed, you can only
*encode* strings, but not decode them.

> This may or may not be a problem

The problem is this:

py> hashlib.sha1(b"Hallo").hexdigest().decode("hex")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'

Regards,
Martin



More information about the Python-list mailing list