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


Groups > comp.lang.python > #98701

Re: new to python, help please !!

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: new to python, help please !!
Date 2015-11-12 16:41 +0100
Organization None
Message-ID <mailman.274.1447342924.16136.python-list@python.org> (permalink)
References <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <20151111110655.7293d3b7@bigbox.christie.dr> <n229b9$hh9$1@ger.gmane.org> <20151112090058.0834a645@bigbox.christie.dr>

Show all headers | View raw


Tim Chase wrote:

> On 2015-11-12 15:56, Peter Otten wrote:
>> Tim Chase wrote:
>> 
>> >   with open("file1.md5") as a, open("file2.md5") as b:
>> >     for s1, s2 in zip(a, b):
>> >       if s1 != s2:
>> >         print("Files differ")
>> 
>> Note that this will not detect extra lines in one of the files.
>> I recommend that you use itertools.zip_longest (izip_longest in
>> Python 2) instead of the built-in zip().
> 
> Yeah, I noticed that after pushing <send> but then posted a later
> version that just read chunks of the file which should catch that
> file-size difference.  Or, as in that other message, prefix it with
> an fstat() check to compare file-sizes so that you don't even have to
> open the files if the sizes differ.
> 
> -tkc

>>> os.path.getsize("file1.md5")
10
>>> os.path.getsize("file2.md5")
10
>>> with open("file1.md5") as a, open("file2.md5") as b:
...     for s, t in zip(a, b):
...         if s != t: print("different")
... 
>>> from itertools import zip_longest
>>> with open("file1.md5") as a, open("file2.md5") as b:
...     for s, t in zip_longest(a, b):
...         if s != t: print("different")
... 
different

I admit I cheated and used Python 3 ;)

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