Fixed mx.DateTime or alternative?

M.-A. Lemburg mal at lemburg.com
Mon Jul 9 17:36:26 EDT 2001


Chuck Esterbrook wrote:
> 
> At 01:15 PM 7/9/2001 +0200, M.-A. Lemburg wrote:
> >Side note:
> >
> >         if x is None: ...
> >
> >is a possible workaround which is faster than using "==" !
> 
> I switched to that, but then there is this left over:
> 
>          if a==b:
> 
> where a and b are literally variables and could both be DateTimes, but one
> of them ends up being None and the exception occurs. Someone suggested I
> could use:
> 
>          if str(a)==str(b):
> 
> although before I got that suggestion, I just wrapped it with a try: and
> assumed inequality.

In this case you could use:

	if a and b and (a == b): ...

(DateTime instances are always true, None is false)

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/





More information about the Python-list mailing list