Using filepath method to identify an .html page
Peter Otten
__peter__ at web.de
Tue Jan 22 10:25:42 EST 2013
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'
;)
More information about the Python-list
mailing list