Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cache': 0.05; 'python': 0.09; 'filename.': 0.09; 'received:209.85.212.54': 0.09; 'script,': 0.09; 'subject:method': 0.09; 'def': 0.10; 'coding?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'written.': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'specify': 0.17; 'subject:page': 0.17; 'jan': 0.18; 'load': 0.19; 'code.': 0.20; 'supposed': 0.21; 'please?': 0.22; 'work,': 0.22; 'this:': 0.23; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'skip:( 20': 0.28; 'code': 0.31; 'subject: .': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'skip:f 40': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'bad': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'end': 0.40; 'your': 0.60; 'real': 0.61; 'save': 0.61; 'dont': 0.64; 'hey,': 0.72; '2013': 0.84; 'column.': 0.84; 'subject:Using': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=qBwWeb+4Wd9iDMExu5xt2UnpodGXHZSR/9wPn1P25Hw=; b=WGq+OeecU+AfqbK3IXgISaVd3H6xG3FOY2SkwLy1dVB4pUxJKYepOUJgy4ijVGGUlA uuYc6kzUx7WY2w6CEawpXE7wwR05Ps5DSX+K9hgaKIQJsu5M405IwfGUCfmuNwBiIdIc UlZKnJAIAvu4YsKUeJ8u//DR/Yngz3A5SXbyEnHh3JHrN/lBDatItpK9YiK8oLYhqlHP u/BBpS+6Lc0JZSN3ev19ZFP3nr+XmjewwJ0nOoX/e3kPBC1woZI+XQ4At+6Y5+F2Kw7B QUmRBMcH5i65ijT7FKRIkEg3mry32mF/93MNE9S50TPVn2M0kORYZS6FpX/u1Jz6fXgl RHAw== MIME-Version: 1.0 X-Received: by 10.52.29.109 with SMTP id j13mr16669699vdh.111.1358867277475; Tue, 22 Jan 2013 07:07:57 -0800 (PST) In-Reply-To: References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> Date: Wed, 23 Jan 2013 02:07:57 +1100 Subject: Re: Using filepath method to identify an .html page From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358867285 news.xs4all.nl 6930 [2001:888:2000:d::a6]:33926 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37280 On Wed, Jan 23, 2013 at 1:55 AM, 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.... def function_that_returns_a_number_out_of_a_string(string, cache=[]): return cache.index(string) if string in cache else (cache.append(string) or len(cache)-1) That will work perfectly, as long as you don't care how long the numbers end up, and as long as you have a single Python script doing the work, and as long as you make sure you save and load that cache any time you shut down the script, and so on. It will also, and rightly, be decried as a bad idea. But hey, you did specify that it be one line of code. For your real job, USE A DATABASE COLUMN. ChrisA