New coder developing script for use in my day job. Trying to make a class which take user entered month and year and combines them into date object. I can get the code for date entry and parsing into date object working. but then trying to make into a class so I can used over and over in difference instances which I cant seem to get right. I pasted where I currently am in my trial and error. I have been through many iterations trying to make it work. Any advice would be appreciated
See above
class User_Input_Date():
def __ini__(self):
self.month_input = input('What was the month (1-12)').strip()
if self.month_input in ['01', '1', 'Jan', 'January', 'jan', 'january']:
self.month_input = 1
elif self.month_input in ['02', '2', 'Feb', 'February', 'feb', 'february']:
self.month_input = 2
elif self.month_input in ['03', '3', 'Mar', 'March', 'mar', 'march']:
self.month_input = 3
elif self.month_input in ['04', '4', 'Apr', 'April', 'apr', 'april']:
self.month_input = 4
elif self.month_input in ['05', '5', 'May', 'may']:
self.month_input = 5
elif self.month_input in ['06', '6', 'Jun', 'June', 'jun', 'june']:
self.month_input = 6
elif self.month_input in ['07', '7', 'Jul', 'July', 'jul', 'july']:
self.month_input = 7
elif self.month_input in ['08', '8', 'Aug', 'August', 'aug', 'august']:
self.month_input = 8
elif self.month_input in [
'09', '9', 'Sept', 'September', 'sept', 'september'
]:
self.month_input = 9
elif self.month_input in ['10', 'Oct', 'October', 'oct', 'october']:
self.month_input = 10
elif self.month_input in ['11', 'Nov', 'November', 'nov', 'november']:
self.month_input = 11
elif self.month_input in ['12', 'Dec', 'December', 'dec', 'december']:
self.month_input = 12
else:
self.month_input = None
self.year_input = input('What was the year?').strip()
def Combined_User_Input_Date(self):
combine_date_user_input_month_year = datetime.date(
self.year_input, self.month_input, day=1)
return combine_date_user_input_month_year.strftime("%m" + "-" + "%Y")
primary_bariatric_date = User_Input_Date()
primary_bariatric_date.Combined_User_Input_Date()
Tell me my year input not defined. Exact text below:
Traceback (most recent call last):
File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py", line 64, in <module>
primary_bariatric_date.Combined_User_Input_Date()
File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/test.py", line 59, in Combined_User_Input_Date
self.year_input, self.month_input, day=1)
AttributeError: 'User_Input_Date' object has no attribute 'year_input'