Clashing cmp
tre17 at student.canterbury.ac.nz
tre17 at student.canterbury.ac.nz
Wed Sep 22 04:03:06 EDT 1999
Andrew Dalke <dalke at bioreason.com> writes:
[discussion of `cmp' name clash snipped]
>
> Here was my workaround:
>
> # "cmp" module compares two files using the cmp() function.
> # Work around an ugliness in Python since cmp() is also a builtin!
> old_cmp = cmp
> from cmp import cmp
> file_compare = cmp
> cmp = old_cmp
>
> It was nice to have the functionality handy. I can say, though,
> that I started by looking for it in shutil, since I figured it
> was natural to have file "compare" next to "copy" and "rmtree".
>
> So I would have no problem moving the cmp functionality (the
> functions "cmp" and "do_cmp") into shutil and renaming "cmp"
> to "file_compare" and "do_cmp" to "do_file_compare".
Or, for those that really like __ names, use one peice of ugliness to
solve another:
>>> filecmp = __import__('cmp')
I have sometimes thought that it would be nice to have something like:
>>> import cmp as filecmp
or even:
>>> import cPickle as pickle
But that's probably just going to be way to open to abuse. In the
first example at least it's obvious that something weird is happening.
--
Tim Evans
More information about the Python-list
mailing list