new to python, help please !!

paul.hermeneutic at gmail.com paul.hermeneutic at gmail.com
Thu Nov 12 09:27:29 EST 2015


Would some form of subprocess.Popen() on cmp or fc /b be easier?
On Nov 12, 2015 7:13 AM, "Tim Chase" <python.list at tim.thechases.com> wrote:

> On 2015-11-12 08:21, Marko Rauhamaa wrote:
> > 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:
> >            ...
>
> Though that suffers if the files are large.  Might try
>
>   CHUNK_SIZE = 4 * 1024 # read 4k chunks
>   # chunk_offset = 0
>   with open('f1.md5') as f1, open('f2.md5') as f2:
>     while True:
>       c1 = f1.read(CHUNK_SIZE)
>       c2 = f2.read(CHUNK_SIZE)
>       if c1 or c2:
>         # chunk_offset += 1
>         if c1 != c2:
>           not_the_same(c1, c2)
>           # not_the_same(chunk_offset * CHUNK_SIZE, c1, c2)
>           break
>       else: # EOF
>         the_same()
>         break
>
> which should perform better if the files are huge
>
> -tkc
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list