I am using MVC (Module-View-Controller) pattern in my project. I want to keep my code DRY(Don't repeat yourself) so I don't want to write get_date function again just for another input.
I use function get_date() several times, but with different inputs. How can I pass these inputs to function get_date() so it could work?
Here I call get_date() function:
date = get_date(date_input = provide_date())
Here I want to pass the function with input message:
def get_date(date_input):
ask = True
while ask:
date_input
try:
validation = datetime.strptime(date_input, '%Y-%m-
%d').strftime('%Y-%m-%d')
date_list = validation.split('-')
correct_date =
date(int(date_list[0]),int(date_list[1]),int(date_list[2]))
return correct_date
ask = False
except ValueError:
wrong_input()
Provide_date function is:
def provide_date():
return input('Type date in format Y-M-D: ')
I have another inputs for different situations like reschedule with another message.
How can I pass this input to get_date() function so it could work inside While loop? Cause now it loops forever when I raise TypeError.
date_inputdoes not do anything. Did you mean to passdate_inputto the function (instead ofdate_input()) and then calldate_input()on that line? The two are not equivalent.