How to use cmp() function to compare 2 files?
samuel.y.l.cheung at gmail.com
samuel.y.l.cheung at gmail.com
Tue Feb 27 10:37:09 EST 2007
On Feb 27, 12:07 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> In <1172553141.665287.65... at 8g2000cwh.googlegroups.com>, ying... at gmail.com
> wrote:
>
> > File "./scripts/regressionTest.py", line 30, in getSnapShot
> > if (difflib.context_diff(f1.readlines(), f2.readlines()).len() ==
> > 0):
> > # no difference
> > else:
> > # files are different
> > AttributeError: 'generator' object has no attribute 'len'
>
> > Can you please help?
>
> The function returns a generator/iterator over the differences which has
> no `len()` method. If you just want to know if two files are equal or not
> use `filecmp.cmp()`. Read the docs about the `shallow` argument of that
> function.
>
> Ciao,
> Marc 'BlackJack' Rintsch
Thanks. I use that before, it does not work for me, since it always
return 1, regardless if the file content of 2 files are different or
not.
More information about the Python-list
mailing list