Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: new to python, help please !! Date: Thu, 12 Nov 2015 16:41:33 +0100 Organization: None Lines: 40 Message-ID: References: <93aef8e5-3d6f-41f4-a625-cd3c2007686e@googlegroups.com> <20151111110655.7293d3b7@bigbox.christie.dr> <20151112090058.0834a645@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de CsqNNEYJYM9PGEzSQ4wfLwklihUtsNTypMiKQKowS7UQ== Return-Path: 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; 'prefix': 0.07; 'subject:help': 0.07; 'chunks': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'yeah,': 0.09; 'python': 0.10; 'files.': 0.13; 'subject:python': 0.14; '-tkc': 0.16; 'b):': 0.16; 'itertools': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'later': 0.16; 'detect': 0.18; '>>>': 0.20; 'posted': 0.21; 'import': 0.24; 'tim': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'compare': 0.27; 'chase': 0.29; 'noticed': 0.32; 'open': 0.33; 'file': 0.34; 'subject:please': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'instead': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'skip:z 10': 0.38; 'version': 0.38; 'files': 0.38; 'or,': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'different': 0.63; 'difference.': 0.84; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8576.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98701 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 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 ;)