You probably want something like overload/multiple dispatch. I quick search
on PyPI yields a 'multipledispatch' package.

I never used, however.

On Wed, May 11, 2022 at 08:36:26AM -0700, Tobiah wrote:
On 5/11/22 06:33, Michael F. Stemper wrote:
I have a function that I use to retrieve daily data from a
home-brew database. Its calling sequence is;

def TempsOneDay( year, month, date ):

After using it (and its friends) for a few years, I've come to
realize that there are times where it would be advantageous to
invoke it with a datetime.date as its single argument.

You could just use all keyword args:

def TempsOneDay(**kwargs):

       if 'date' in kwargs:
               handle_datetime(kwargs['date'])
       elif 'year' in kwargs and 'month' in kwargs and 'day' in kwargs:
               handle_args(kwargs['year'], kwargs['month'], kwargs['day'])
       else:
               raise Exception("Bad keyword args")

TempsOneDay(date=datetime.datetime.now)

TempsOneDay(year=2022, month=11, day=30)

--
https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to