Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.04; 'fails.': 0.09; 'hashlib': 0.09; "object's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; ':-)': 0.13; 'value.': 0.15; '"md5': 0.16; 'emanuele': 0.16; 'hashed': 0.16; 'instance)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'snippets': 0.16; 'string': 0.17; 'instance': 0.17; 'integer': 0.17; 'subject:page': 0.17; '(in': 0.18; '>>>': 0.18; 'import': 0.21; 'absolute': 0.23; 'statement': 0.23; 'header:User-Agent:1': 0.26; '[1]': 0.27; 'header:X-Complaints-To:1': 0.28; 'hash': 0.29; 'methods.': 0.29; 'writes:': 0.29; 'no,': 0.29; 'skip:_ 10': 0.29; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'subject: .': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'path': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'test': 0.36; 'problems': 0.36; 'does': 0.37; 'why': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'skip:a 30': 0.60; 'easy': 0.60; 'most': 0.61; 'pin': 0.65; 'yourself': 0.77; 'quando': 0.84; 'subject:Using': 0.84; 'why?': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lele Gaifax Subject: Re: Using filepath method to identify an .html page Date: Tue, 22 Jan 2013 13:22:02 +0100 Organization: Nautilus Entertainments References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 78-134-97-76.v4.ngi.it User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:txair5ZKb8hPczqYC8njxMJEJWI= 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358857341 news.xs4all.nl 6971 [2001:888:2000:d::a6]:59914 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37263 Ferrous Cranus writes: > 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 No, that statement does not "convert" a string into another, but rather returns a "md5 HASH object": >>> import hashlib >>> hashlib.md5('foo') Consulting the hashlib documentation[1], you could learn about that object's methods. > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number > > Why this fails? Because in general you can't "convert" an arbitrary object instance (in your case an hashlib.HASH instance) to an integer value. Why do you need an integer? Isn't hexdigest() what you want? >>> print _.hexdigest() acbd18db4cc2f85cedef654fccc4a4d8 Do yourself a favor and learn using the interpreter to test your snippets line by line, most problems will find an easy answer :-) ciao, lele. [1] http://docs.python.org/2.7/library/hashlib.html#module-hashlib -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.