Τη Τρίτη, 22 Ιανουαρίου 2013 2:47:16 μ.μ. UTC+2, ο χρήστης Ferrous Cranus 
έγραψε:
> Τη Τρίτη, 22 Ιανουαρίου 2013 2:29:21 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> 
> > On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> 
> > 
> 
> > > # 
> > > ====================================================================================================================================
> 
> > 
> 
> > > # produce a hash string based on html page's filepath and convert it to 
> > > an integer, that will then be used to identify the page itself
> 
> > 
> 
> > > # 
> > > ====================================================================================================================================
> 
> > 
> 
> > >
> 
> > 
> 
> > > 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
> 
> > 
> 
> > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to 
> > > a number
> 
> > 
> 
> > >
> 
> > 
> 
> > > Why this fails?
> 
> > 
> 
> > >
> 
> > 
> 
> > 
> 
> > 
> 
> > Is your copy/paste broken?  It could be useful to actually show in what 
> 
> > 
> 
> > way it "fails."
> 
> > 
> 
> > 
> 
> > 
> 
> > The md5 method produces a "HASH object", not a string.  So int() cannot 
> 
> > 
> 
> > process that.
> 
> > 
> 
> > 
> 
> > 
> 
> > To produce a digest string from the hash object, you want to call 
> 
> > 
> 
> > hexdigest() method.  The result of that is a hex literal string.  So you 
> 
> > 
> 
> > cannot just call int() on it, since that defaults to decimal.
> 
> > 
> 
> > 
> 
> > 
> 
> > To convert a hex string to an int, you need the extra parameter of int:
> 
> > 
> 
> > 
> 
> > 
> 
> >     int(mystring, 16)
> 
> > 
> 
> > 
> 
> > 
> 
> > Now, see if you can piece it together.
> 
> > 
> 
> 
> 
> 
> 
> htmlpage = a string respresenting the absolute path of the requested .html 
> file 
> 
> 
> 
> 
> 
> What i want to do, is to associate a number to an html page's absolute path 
> for to be able to use that number for my database relations instead of the 
> BIG absolute path string.
> 
> 
> 
> so to get an integer out of a string i would just have to type:
> 
> 
> 
> pin = int( htmlpage )
> 
> 
> 
> But would that be unique?

Another error even without hasing anyhting http://superhost.gr to view it please
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to