Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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.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; 'digest': 0.15; 'decimal.': 0.16; 'hashed': 0.16; 'hex': 0.16; 'md5': 0.16; 'string': 0.17; 'wrote:': 0.17; 'subject:page': 0.17; 'together.': 0.21; 'int,': 0.22; 'produces': 0.22; 'absolute': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'object,': 0.27; 'hash': 0.29; 'piece': 0.29; 'convert': 0.29; 'that.': 0.30; 'file': 0.32; 'could': 0.32; 'subject: .': 0.33; 'to:addr:python- list': 0.33; 'path': 0.35; 'method': 0.36; 'useful': 0.36; 'itself': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'identify': 0.61; 'show': 0.63; 'pin': 0.65; 'received:74.208': 0.71; 'subject:Using': 0.84; 'why?': 0.84 Date: Tue, 22 Jan 2013 07:29:21 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:By0574n96uJYjKLkLz0GVHj9YP/w3+AoILb+n6fAG5j V19fO5HLpkiq3Azjt+1rSRbGx8cO9uY32xEYru26kGtqloSaQX ZCVHr98rAk0QJX61LB7/Pvn7Rb7phzw8WO+9X3ByFL5usa60WQ uhVcEnc27fzrwfEoh+BqjtmINin2HgAQvIDkNZRQnzBKsI2owx wClF9i4nyb6JyGAWbX3tbUmkbgzUfbnIroc/D9EbtlMSLuBKJ7 5YlMkxm1H4s2amRKfyfBnfQkavXAc67jpZI3GSs3KV/XJK1E+a J61+5yAlhp3zGQNTBy4YFrkmDjjdYUxTPo7jWDJMyC1cx55GQ= = 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358857784 news.xs4all.nl 6891 [2001:888:2000:d::a6]:37195 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37265 On 01/22/2013 07:02 AM, Ferrous Cranus wrote: > # ==================================================================================================================================== > # 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 > # ==================================================================================================================================== > > pin = int( hashlib.md5( htmlpage ) ) > > This fails. why? > > htmlpage = a string respresenting the absolute path of the requested .html file > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > Why this fails? > Is your copy/paste broken? It could be useful to actually show in what way it "fails." The md5 method produces a "HASH object", not a string. So int() cannot process that. To produce a digest string from the hash object, you want to call hexdigest() method. The result of that is a hex literal string. So you cannot just call int() on it, since that defaults to decimal. To convert a hex string to an int, you need the extra parameter of int: int(mystring, 16) Now, see if you can piece it together. -- DaveA