Using filepath method to identify an .html page

Ferrous Cranus nikos.gr33k at gmail.com
Tue Jan 22 10:59:58 EST 2013


Τη Τρίτη, 22 Ιανουαρίου 2013 5:25:42 μ.μ. UTC+2, ο χρήστης Peter Otten έγραψε:
> Ferrous Cranus wrote:
> 
> 
> 
> > I insist, perhaps compeleld, to use a key to associate a number to a
> 
> > filename. Would you help please?
> 
> > 
> 
> > I dont know this is supposed to be written. i just know i need this:
> 
> > 
> 
> > number = function_that_returns_a_number_out_of_a_string(
> 
> > absolute_path_of_a_html_file)
> 
> > 
> 
> > Would someone help me write that in python coding? We are talkign 1 line
> 
> > of code here....
> 
> 
> 
> Since you insist:
> 
> 
> 
> >>> def function_that_returns_a_number_out_of_a_string(absolute_path_of_a_html_file):
> 
> ...     return int(absolute_path_of_a_html_file.encode("hex"), 16)
> 
> ... 
> 
> >>> function_that_returns_a_number_out_of_a_string("/foo/bar/baz")
> 
> 14669632128886499728813089146L
> 
> 
> 
> As a bonus here is how to turn the number back into a path:
> 
> 
> 
> >>> x = 14669632128886499728813089146
> 
> >>> "{:x}".format(x).decode("hex")
> 
> '/foo/bar/baz'
> 
> 
> 
> ;)

Thank you but no...no that would be unnecessary complex.

I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :(



More information about the Python-list mailing list