Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'defaults': 0.05; 'method.': 0.05; 'parameter': 0.07; '16)': 0.09; 'fails.': 0.09; 'integer,': 0.09; 'literal': 0.09; 'subject:method': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'do,': 0.15; 'digest': 0.15; 'decimal.': 0.16; 'hashed': 0.16; 'hex': 0.16; 'md5': 0.16; 'type:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; 'subject:page': 0.17; 'together.': 0.21; 'int,': 0.22; 'produces': 0.22; 'cc:2**0': 0.23; 'absolute': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'object,': 0.27; 'received:209.85.212': 0.28; 'hash': 0.29; 'piece': 0.29; 'convert': 0.29; 'that.': 0.30; 'file': 0.32; 'could': 0.32; 'subject: .': 0.33; 'received:google.com': 0.34; 'path': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'useful': 0.36; 'itself': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'page': 0.38; 'instead': 0.39; 'your': 0.60; 'identify': 0.61; 'relations': 0.62; 'show': 0.63; 'pin': 0.65; '8bit%:100': 0.70; '8bit%:92': 0.70; '2013': 0.84; 'subject:Using': 0.84; 'why?': 0.84; 'angel': 0.93 X-Received: by 10.49.58.167 with SMTP id s7mr4515967qeq.5.1358858836896; Tue, 22 Jan 2013 04:47:16 -0800 (PST) Newsgroups: comp.lang.python Date: Tue, 22 Jan 2013 04:47:16 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.68.70.179; posting-account=DYJQ-woAAACEPH85Au2BhUVfFTfSfVa4 References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 94.68.70.179 MIME-Version: 1.0 Subject: Re: Using filepath method to identify an .html page From: Ferrous Cranus To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: , Message-ID: Lines: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358858844 news.xs4all.nl 6903 [2001:888:2000:d::a6]:42885 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37267 =CE=A4=CE=B7 =CE=A4=CF=81=CE=AF=CF=84=CE=B7, 22 =CE=99=CE=B1=CE=BD=CE=BF=CF= =85=CE=B1=CF=81=CE=AF=CE=BF=CF=85 2013 2:29:21 =CE=BC.=CE=BC. UTC+2, =CE=BF= =CF=87=CF=81=CE=AE=CF=83=CF=84=CE=B7=CF=82 Dave Angel =CE=AD=CE=B3=CF=81= =CE=B1=CF=88=CE=B5: > On 01/22/2013 07:02 AM, Ferrous Cranus wrote: >=20 > > # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > > # produce a hash string based on html page's filepath and convert it to= an integer, that will then be used to identify the page itself >=20 > > # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > > >=20 > > pin =3D int( hashlib.md5( htmlpage ) ) >=20 > > >=20 > > This fails. why? >=20 > > >=20 > > htmlpage =3D a string respresenting the absolute path of the requested = .html file >=20 > > hashlib.md5( htmlpage ) =3D conversion of the above string to a hashed = string >=20 > > int( hashlib.md5( htmlpage ) ) =3D conversion of the above hashed strin= g to a number >=20 > > >=20 > > Why this fails? >=20 > > >=20 >=20 >=20 > Is your copy/paste broken? It could be useful to actually show in what= =20 >=20 > way it "fails." >=20 >=20 >=20 > The md5 method produces a "HASH object", not a string. So int() cannot= =20 >=20 > process that. >=20 >=20 >=20 > To produce a digest string from the hash object, you want to call=20 >=20 > hexdigest() method. The result of that is a hex literal string. So you= =20 >=20 > cannot just call int() on it, since that defaults to decimal. >=20 >=20 >=20 > To convert a hex string to an int, you need the extra parameter of int: >=20 >=20 >=20 > int(mystring, 16) >=20 >=20 >=20 > Now, see if you can piece it together. >=20 htmlpage =3D a string respresenting the absolute path of the requested .htm= l file=20 What i want to do, is to associate a number to an html page's absolute path= for to be able to use that number for my database relations instead of the= BIG absolute path string. so to get an integer out of a string i would just have to type: pin =3D int( htmlpage ) But would that be unique?