Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python': 0.09; '16)': 0.09; 'filename.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:f 70': 0.09; 'subject:method': 0.09; 'def': 0.10; 'bonus': 0.13; 'coding?': 0.16; 'path:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'skip:f 60': 0.16; 'written.': 0.16; 'wrote:': 0.17; 'skip:i 40': 0.17; 'subject:page': 0.17; '>>>': 0.18; 'skip:" 30': 0.20; 'supposed': 0.21; 'please?': 0.22; 'this:': 0.23; 'header:User- Agent:1': 0.26; 'skip:1 30': 0.27; 'header:X-Complaints-To:1': 0.28; "skip:' 10": 0.30; 'code': 0.31; 'subject: .': 0.33; 'to:addr:python-list': 0.33; 'skip:f 40': 0.35; 'received:org': 0.36; 'turn': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'back': 0.62; 'dont': 0.64; 'here': 0.65; 'subject:Using': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Using filepath method to identify an .html page Date: Tue, 22 Jan 2013 16:25:42 +0100 Organization: None References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a038.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358868351 news.xs4all.nl 6871 [2001:888:2000:d::a6]:47283 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37284 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' ;)