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


Groups > comp.lang.python > #98674

Re: new to python, help please !!

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: new to python, help please !!
Date Thu, 12 Nov 2015 08:21:14 +0200
Organization A noiseless patient Spider
Lines 30
Message-ID <8737wbu49x.fsf@elektro.pacujo.net> (permalink)
References <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <obL0y.222880$6i2.63495@fx35.am4> <5644005e$0$2932$c3e8da3$76491128@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="6457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uJ1fZ4K0wfUjMWZF+W8Cd"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:U9ihR/LzQtOlSd6R82TzJxySXFk= sha1:uviffTrk12GpR7nZRaw/VGpRzFQ=
Xref csiph.com comp.lang.python:98674

Show key headers only | View raw


Steven D'Aprano <steve+comp.lang.python@pearwood.info>:

> On Thursday 12 November 2015 04:48, Quivis wrote:
>
>> On Wed, 11 Nov 2015 08:34:30 -0800, Anas Belemlih wrote:
>> 
>>> md5
>> 
>> If those are md5 values stored inside files, wouldn't it be easier to
>> just hash them?
>> 
>> import hashlib
>> 
>> m1 = hashlib.sha224(open('f1').read()).hexdigest()
>> m2 = hashlib.sha224(open('f2').read()).hexdigest()
>
> I presume that the purpose of the exercise is to learn basic Python
> skills like looping.

And if you really wanted to compare two files that are known to contain
MD5 checksums, the simplest way is:

   with open('f1.md5') as f1, open('f2.md5') as f2:
       if f1.read() == f2.read():
           ...
       else:
           ...


Marko

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


Thread

new to python, help please !! Anas Belemlih <anas.belemlih@gmail.com> - 2015-11-11 08:34 -0800
  Re: new to python, help please !! John Gordon <gordon@panix.com> - 2015-11-11 16:58 +0000
  Re: new to python, help please !! Tim Chase <python.list@tim.thechases.com> - 2015-11-11 11:06 -0600
  Re: new to python, help please !! Ben Finney <ben+python@benfinney.id.au> - 2015-11-12 04:16 +1100
  Re: new to python, help please !! Quivis <quivis@domain.invalid> - 2015-11-11 17:48 +0000
    Re: new to python, help please !! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-11-12 13:58 +1100
      Re: new to python, help please !! Marko Rauhamaa <marko@pacujo.net> - 2015-11-12 08:21 +0200
        Re: new to python, help please !! Tim Chase <python.list@tim.thechases.com> - 2015-11-12 05:48 -0600
        Re: new to python, help please !! <paul.hermeneutic@gmail.com> - 2015-11-12 07:27 -0700
      Re: new to python, help please !! Quivis <quivis@domain.invalid> - 2015-11-12 17:55 +0000
        Re: new to python, help please !! Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-12 19:49 +0000
  Re: new to python, help please !! Peter Otten <__peter__@web.de> - 2015-11-12 15:56 +0100
  Re: new to python, help please !! Tim Chase <python.list@tim.thechases.com> - 2015-11-12 09:00 -0600
  Re: new to python, help please !! Peter Otten <__peter__@web.de> - 2015-11-12 16:41 +0100
  Re: new to python, help please !! Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-12 21:24 +0000

csiph-web