Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Does': 0.04; '"""': 0.07; 'see:': 0.07; 'python': 0.08; 'called.': 0.09; 'defined.': 0.09; 'wed,': 0.12; 'stored': 0.13; 'subject:file': 0.13; 'wrote:': 0.15; 'occurs.': 0.16; 'twice.': 0.16; 'object,': 0.16; 'cc:addr:python-list': 0.16; 'pm,': 0.16; 'def': 0.16; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply- To:1': 0.22; 'expect': 0.25; 'function': 0.26; 'message- id:@mail.gmail.com': 0.28; 'object': 0.30; 'cc:addr:python.org': 0.30; 'definition': 0.30; 'objects.': 0.30; 'subject:support': 0.30; 'least': 0.31; 'subject:?': 0.31; 'does': 0.32; 'there': 0.34; 'url:python': 0.37; 'passed': 0.37; 'received:google.com': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'two': 0.38; 'returned': 0.39; 'url:docs': 0.39; 'received:209': 0.40; 'where': 0.40; 'subject:mode': 0.84; 'url:reference': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Zf2hZK/nr4yYeeu+PnV/42YwYzXWNuaPZELZNKAgyp0=; b=ge57nwbo9K8wiOtDc4oQrsLMVno+Yzlwmeq2iWUMuC2Hj9dqNqGf4UyQ0cNaiTCPY7 i4oJ5vIJJoFYLTKG6UD33AC6KVN9EBngWNdMphijpKU43lXx7xfdK4D5DGx6vE0Amf28 8STbKmQXahd8lt96jO0WNAUo+C40TACco4K5M= MIME-Version: 1.0 In-Reply-To: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> References: <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com> From: Ian Kelly Date: Wed, 6 Jul 2011 13:48:36 -0600 Subject: Re: Does hashlib support a file mode? To: Phlip Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309981747 news.xs4all.nl 21796 [2001:888:2000:d::a6]:54462 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8980 On Wed, Jul 6, 2011 at 1:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. There is no definition-bending. The code: """ def file_to_hash(path, m = hashlib.md5()): # do stuff... file_to_hash(path1) file_to_hash(path2) """ does not call hashlib.md5 twice. It calls it *once*, at the time the file_to_hash function is defined. The returned object is stored on the function object, and that same object is passed into file_to_hash as a default value each time the function is called. See: http://docs.python.org/reference/compound_stmts.html#function