Comparing file objects: what is compared?

Gerrit Holl gerrit.holl at
Fri Feb 11 21:36:40 CET 2000

Fred L. Drake, Jr. wrote on 950270973:
> Gerrit Holl writes:
>  > >>> 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?
>   The ID is used for when nothing else is meaningful (and clear).
> It's arbitrary & consistent.  ;)

This does not seem to be documented anywhere! Am I missing it or am I right?
I think it should be documented, something like:
If objects being larger or smaller seems meaningless, like with file objects,
the result is pretty arbitrary: the internal id (as returned by the id()
builtin function) is used.

Or as a FAQ. Or a an IAQ, since it's not asked Frequently but Infrequently
instead :)


Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O
!M !V PS+ PE? Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK----- moc.edockeeg.www//:ptth

More information about the Python-list mailing list