Form sha1.hexdigest to sha1.digest

L

LMZ

How can convert string from sha1.hexdigest() to string that is the
same, like from sha1.digest()

thanks for your help!

Alexandr.
 
M

Martin v. Löwis

Or hexdigest_string.decode('hex')

I would advise against this, as it's incompatible with Python 3.

Regards,
Martin
 
M

marek.rocki

Martin v. Löwis napisa³(a):
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. This may or may not be a problem (bytes type is
supposed to be immutable, so it can be used in many places where a
string is used now, ex. as a dict key).
 
M

Martin v. Löwis

Or hexdigest_string.decode('hex')
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top