Comparing file objects: what is compared?

Fredrik Lundh effbot at telia.com
Fri Feb 11 17:13:30 EST 2000


Gerrit Holl <gerrit.holl at pobox.com> wrote:
> >>> 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?

http://www.python.org/doc/current/ref/comparisons.html
tells you how comparisions work.  this case falls in the
"other types" category:

    "Most other types compare unequal unless they are
    the same object; the choice whether one object is
    considered smaller or larger than another one is made
    arbitrarily but consistently within one execution of a
    program."

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list