[egenix-users] cmp() function

M.-A. Lemburg mal at egenix.com
Mon Dec 19 15:02:19 CET 2005


Dirk Holtwick wrote:
> Hi,
> 
> in mx.DateTime there is a function called "cmp". Described like this in
> the documentation:
> 
> "... There is a special compare function included (cmp()) in the package
> that allows you to compare two date/time values using a given accuracy,
> e.g. cmp(date1,date2,0.5) will allow 12:00:00.5 and 12:00:01.0 to
> compare equal."
> 
> I think this function conflicts with the system function cmp() used e.g.
> by sort() if you import DateTime like this:
> 
> from mx.DateTime import *
> 
> Would'nt it be better to name it "datecmp" or similar or a least
> implement a fallback to the system cmp function instead of raising an
> exception?

No. In fact, the cmp() function was named deliberately after
the builtin one. Falling back to the system one would only
hide a programming error.

In summary: You should never do "from mx.DateTime import *" -
that's bad style :-)

I tend to always write:

from mx import DateTime
...
d = DateTime.now()

Makes reading the code a lot easier too, esp. if you regularly
work with or on large frameworks

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Dec 19 2005)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the egenix-users mailing list