datelib pythonification

alex goretoy agoretoy at
Wed Mar 10 07:58:13 CET 2010

> DATE_TYPE = type(

def dates_diff(self, *targs):

   nargs = len(targs)

   if nargs == 0:

       return self.enddate - self.startdate

   if nargs == 1:

       arg = targs[0]

       if not isinstance(arg, (list, tuple)) or len(arg) != 2:

           raise Exception(

               "single arg must be list or tuple of length 2")

       start, end = arg

   elif nargs == 2:

       start, end = targs


       raise Exception("expected 0,1, or 2 args; found %d" % nargs)

   if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE):

       return end - start

   raise Exception("both values must be of type DATE_TYPE")

> HTH,

> John

This is awesome. Thank you for your contribution. I wasn't sure anyone was
gonna reply; just saw your reply, pardon my delay. I will make the changes
you suggested to other functions that apply in the lib as well(mimic that
style of coding). Make it so it raises exceptions instead of failing over
quietly(fallback to the __init__ passed args in other words).

Is There any other functions or methods that you would recommend be added to
the lib?

Any and all other suggestions are welcome. I love python and you guys are
practically helping me expand on my knowledge in this realm :)

I haven't touched it in a little bit so after I mess with it again I'll be
able to add more this thread/lib or whatever.

Thanks Again,
-Alex Goretoy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list