python - __init__ method that takes multiple arguments -


this question has answer here:

i did create new datetime.date object

class workdate(datetime.date):     pass 

the functionality of workdate is(not important question) when add timedelta object move weekday date. ie when add timedelta(1) on friday dated workdate return next monday dated workdate.


how can __init__ workdate 1 of these 2 method create same result

x = workdate(2017, 8, 3) y = workdate(datetime.date(2017, 8, 3)) 


did try not working initialization date object

class workdate(datetime.date):     def __init__(self, *args):         if len(args) == 3:             super(workdate, self).__init__(args[0], args[1], args[2])         elif len(args) == 1:             self.year = args[0].year             self.month = args[0].month             self.day = args[0].day 

since want support number of arguments, accept *args .

then, in __init__, pass these __init__ of base class.

def __init__(*args):     super(workdate, self).__init__(*args) 

here's version python 3, added support named (keyword) arguments `**kwargs':

def __init__(*args, **kwargs):     super().__init__(*args, **kwargs) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -