Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'algorithm': 0.03; 'string.': 0.04; 'binary': 0.05; 'paths': 0.05; 'column': 0.07; 'python': 0.09; 'args,': 0.09; 'indexes': 0.09; 'path)': 0.09; 'string)': 0.09; 'subject:method': 0.09; 'index': 0.13; 'charset:iso-8859-7': 0.15; '"unique"': 0.16; '12:57': 0.16; '794': 0.16; 'costing': 0.16; 'easier.': 0.16; 'entries.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'ids.': 0.16; 'really?': 0.16; 'uniqueness': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance,': 0.17; 'integer': 0.17; 'skip': 0.17; 'subject:page': 0.17; 'test.': 0.17; 'jan': 0.18; 'sort': 0.21; 'keys': 0.22; 'absolute': 0.23; 'this:': 0.23; "i've": 0.23; 'long,': 0.24; 'header:In-Reply-To:1': 0.25; 'creating': 0.26; 'common': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'there.': 0.28; 'fine': 0.28; 'run': 0.28; 'hosting': 0.28; "d'aprano": 0.29; 'mode.': 0.29; 'steven': 0.29; 'maybe': 0.29; 'that.': 0.30; 'expect': 0.31; 'could': 0.32; 'idle': 0.33; 'instead,': 0.33; 'subject: .': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'produced': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'returning': 0.35; 'so,': 0.35; 'expected': 0.35; 'received:209.85.220': 0.35; 'table': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'should': 0.36; 'bad': 0.37; 'does': 0.37; 'two': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'end': 0.40; 'most': 0.61; 'chance': 0.61; "you'll": 0.62; 'between': 0.63; 'information': 0.63; 'more': 0.63; 'dont': 0.64; 'six': 0.65; '10,000': 0.65; 'foreign': 0.72; '2013': 0.84; 'relation.': 0.84; 'subject:Using': 0.84; 'tree,': 0.84; '1,000,000': 0.91; 'birthday': 0.91; 'imagine': 0.96 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:content-transfer-encoding; bh=Y6yG1ANjx+A6QPXv01EcFF1xQ+QKksIsL0X7e+tDUok=; b=Zyxu0hbSNxmLUEfib9koucvTB6m5kckc99ifwT5GvUzoF3ImEDr+XgcwEpViC9CmUO Q9wk/mxX+PrejMUAU9gF8DMHE8YWuzLBuWRPzxPgwge39NkwGD0l2PoCdQ7+wKTS8Kt/ jla7x5USPXnXGdZ0259rZaYj8gMVGx3R14tnPjt43n4+B7R6jawPn9ZnqYWEhOMvVM5n Yn6ElElMZuqojY8RpbB1wcl/MjomJ4LdIXUZvLqQrj5815LwUNEo+ssJFXL2xsNyz2NG t358TIKknZJSEc90vruzmURQGysCtrkEwd+YLutWnWi+enUDYh6dXYsMGbAVzrSDLphH 1hkw== MIME-Version: 1.0 X-Received: by 10.52.17.70 with SMTP id m6mr20703914vdd.92.1358865183295; Tue, 22 Jan 2013 06:33:03 -0800 (PST) In-Reply-To: <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> 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 01:33:03 +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-7 Content-Transfer-Encoding: quoted-printable 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358865192 news.xs4all.nl 6871 [2001:888:2000:d::a6]:50268 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37275 On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus wr= ote: > =D4=E7 =D4=F1=DF=F4=E7, 22 =C9=E1=ED=EF=F5=E1=F1=DF=EF=F5 2013 3:04:41 = =EC.=EC. UTC+2, =EF =F7=F1=DE=F3=F4=E7=F2 Steven D'Aprano =DD=E3=F1=E1=F8= =E5: > >> What do you expect int("my-web-page.html") to return? Should it return 2= 3 >> or 794 or 109432985462940911485 or 42? > > I expected a unique number from the given string to be produced so i coul= d have a (number <=3D> string) relation. What does int( somestring ) is ret= urning really? i don;t have IDLE to test. Just run python without any args, and you'll get interactive mode. You can try things out there. > This counter.py will work on a shared hosting enviroment, so absolutes pa= ths are BIG and expected like this: > > /home/nikos/public_html/varsa.gr/articles/html/files/index.html That's not big. Trust me, modern databases work just fine with unique indexes like that. The most common way to organize the index is with a binary tree, so the database has to look through log(N) entries. That's like figuring out if the two numbers 142857 and 857142 are the same; you don't need to look through 1,000,000 possibilities, you just need to look through the six digits each number has. > 'pin' has to be a number because if i used the column 'page' instead, jus= t imagine the database's capacity withholding detailed information for each= and every .html requested by visitors!!! Not that bad actually. I've happily used keys easily that long, and expected the database to ensure uniqueness without costing performance. > So i really - really need to associate a (4-digit integer <=3D> htmlpage'= s absolute path) Is there any chance that you'll have more than 10,000 pages? If so, a four-digit number is *guaranteed* to have duplicates. And if you research the Birthday Paradox, you'll find that any sort of hashing algorithm is likely to produce collisions a lot sooner than that. > Maybe it can be done by creating a MySQL association between the two colu= mns, but i dont know how such a thing can be done(if it can). > > So, that why i need to get a "unique" number out of a string. please help= . Ultimately, that unique number would end up being a foreign key into a table of URLs and IDs. So just skip that table and use the URLs directly - much easier. In this instance, there's no value in normalizing. ChrisA