Comparing file objects: what is compared?
Michael Hudson
mwh21 at cam.ac.uk
Fri Feb 11 12:22:17 EST 2000
Gerrit Holl <gerrit.holl at pobox.com> writes:
> Hello,
>
> >>> fp1=open('/tmp/file_one', 'w')
> >>> fp2=open('/tmp/file_two', 'w')
> >>> cmp(fp1, fp2)
> -1
> >>> cmp(fp2, fp1)
> 1
>
> What is compared? The date of creation? The filename? The contents?
>
> I've searched the FAQ, the documentation, the sig archives and the
> newsgroup, but I'm not able to find the answer. What is compared when
> comparing file objects?
>
File objects have no specialized "cmp" method, so get the default
cmp(fp1,fp2) == cmp(id(fp1),id(fp2))
one.
HTH,
Michael
More information about the Python-list
mailing list