Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8983

Re: Does hashlib support a file mode?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'subject:Does': 0.04; 'function,': 0.07; 'python': 0.08; 'executed': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'function:': 0.09; 'message- id:@stoneleaf.us': 0.09; 'none):': 0.09; 'none:': 0.09; 'received:gator410.hostgator.com': 0.09; 'skip:\\ 10': 0.09; '~ethan~': 0.09; 'subject:file': 0.13; 'defined': 0.14; 'wrote:': 0.15; 'fail,': 0.16; 'mode.': 0.16; 'naive': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'pm,': 0.16; '>>>': 0.16; 'def': 0.16; 'once,': 0.19; 'header:In-Reply-To:1': 0.22; 'objects,': 0.23; 'expect': 0.25; 'helpful': 0.26; 'language.': 0.28; "didn't": 0.29; '---': 0.30; 'objects.': 0.30; 'subject:support': 0.30; 'looks': 0.30; 'least': 0.31; 'separate': 0.31; 'subject:?': 0.31; 'initial': 0.33; 'to:addr:python-list': 0.34; 'header:User- Agent:1': 0.34; 'function.': 0.35; 'subject:: ': 0.38; 'two': 0.38; 'should': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'received:websitewelcome.com': 0.65; 'received:184': 0.67; 'storage': 0.67; 'special': 0.67; 'received:69.56': 0.73; 'subject:mode': 0.84; 'surprise': 0.96
Date Wed, 06 Jul 2011 13:24:31 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: Does hashlib support a file mode?
References <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com>
In-Reply-To <5a4867f1-929c-4cde-b47e-4b11de767f39@h38g2000pro.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4387
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.723.1309983006.1164.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309983006 news.xs4all.nl 21855 [2001:888:2000:d::a6]:54297
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8983

Show key headers only | View raw


Phlip wrote:
>> On 2011.07.06 12:38 PM, Phlip wrote:
>>> Python sucks. m = md5() looks like an initial assignment, not a
>>> special magic storage mode. Principle of least surprise fail, and
>>> principle of most helpful default behavior fail.
 >>>
> 
> If I call m = md5() twice, I expect two objects.

You didn't call md5 twice -- you called it once when you defined the 
function.

Phlips naive code:
---
def file_to_hash(path, m = hashlib.md5()):
                        \---------------/
                         happens once, when
                         def line is executed


If you want separate md5 objects, don't create just one when you create 
the function, create one inside the function:

def file_to_hash(path, m = None):
     if m is None:
         m = hashlib.md5()


You should try the Principle of Learning the Language.

~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Does hashlib support a file mode? Phlip <phlip2005@gmail.com> - 2011-07-06 12:07 -0700
  Re: Does hashlib support a file mode? geremy condra <debatem1@gmail.com> - 2011-07-06 15:15 -0400
  Re: Does hashlib support a file mode? Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-06 14:42 -0500
  Re: Does hashlib support a file mode? Mel <mwilson@the-wire.com> - 2011-07-06 15:43 -0400
    Re: Does hashlib support a file mode? Anssi Saari <as@sci.fi> - 2011-07-07 14:29 +0300
      Re: Does hashlib support a file mode? Paul Rudin <paul.nospam@rudin.co.uk> - 2011-07-07 13:13 +0100
  Re: Does hashlib support a file mode? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-06 13:48 -0600
  Re: Does hashlib support a file mode? Ethan Furman <ethan@stoneleaf.us> - 2011-07-06 13:24 -0700

csiph-web