Using filepath method to identify an .html page

Lele Gaifax lele at
Tue Jan 22 13:22:02 CET 2013

Ferrous Cranus <nikos.gr33k at> writes:

> pin = int( hashlib.md5( htmlpage ) )
> This fails. why?
> htmlpage = a string respresenting the absolute path of the requested .html file
> hashlib.md5( htmlpage ) = conversion of the above string to a hashed string

No, that statement does not "convert" a string into another, but rather
returns a "md5 HASH object":

>>> import hashlib
>>> hashlib.md5('foo')
<md5 HASH object @ 0xb76dbcf0>

Consulting the hashlib documentation[1], you could learn about that
object's methods.

> int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
> Why this fails?

Because in general you can't "convert" an arbitrary object instance (in
your case an hashlib.HASH instance) to an integer value. Why do you need
an integer? Isn't hexdigest() what you want?

>>> print _.hexdigest()

Do yourself a favor and learn using the interpreter to test your
snippets line by line, most problems will find an easy answer :-)

ciao, lele.

nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at  |                 -- Fortunato Depero, 1929.

More information about the Python-list mailing list