Converting a string to a number by using INT (no hash method)
John Gordon
gordon at panix.com
Tue Jan 22 13:36:05 EST 2013
In <592233bd-3fc1-4e13-97f8-e11f89fbb0ba at googlegroups.com> Ferrous Cranus <nikos.gr33k at gmail.com> writes:
> > pin int( htmlpage.encode("hex"), 16 ) % 10000
> >
> > It'll give you your number, but there are no guarantees of uniqueness.
> You're looking at more blind random luck using that.
> Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!!
No it isn't; you said you wanted a unique 4-digit number. This method
can return the same 4-digit number for lots of different file paths.
> NOW, if you please explain it to me from the innermost parenthesis please,
> because i do want to understand it!!!
1. Transform the html path string into a (large) hexadecimal number
using the encode() function.
2. Convert the hexadecimal number into a decimal integer using the
int() function.
3. Shrink the integer into the range 0-9999 by using the % operator.
More information about the Python-list
mailing list