How to use cmp() function to compare 2 files?
Jussi Salmela
tiedon_jano at hotmail.com
Tue Feb 27 11:25:20 EST 2007
samuel.y.l.cheung at gmail.com kirjoitti:
> 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.
>
>
I think you are mixing cmp and filecmp.cmp. They are two different beasts.
Cheers,
Jussi
More information about the Python-list
mailing list