May-01-2022, 12:25 PM
I guess you are doing something like:
Then at last you have:
birthday = Date(1994, "July", 1)First, in your __init__() you say Date() expects month as an int. But you are passing a string. Right? So it should be:
(Apr-29-2022, 03:36 PM)blackknite Wrote:class Date(object): def __init__(self, year:int, month:str, day:int):
(Apr-29-2022, 03:36 PM)blackknite Wrote:This is because Months is a subclass of Date. In subclass Month you are referring to "self.Months.names" but "self" would mean it is inside the subclass Month which is not the case. So you must refer to "Date.Months.names".----> 9 assert name.capitalize() in self.Months.names, f'''[ERROR] : No such month {name}...
Error:AttributeError: 'Month' object has no attribute 'Months'
Then at last you have:
self.id = self.Months.names.index(name) self.days = self.Months.days[id] self.name = self.Months.names[id]Here you assign a value to "self.id", but then you are referring to it as "id". Be consequent; it should be:
self.id = Date.Months.names.index(name) self.days = Date.Months.days[self.id] self.name = Date.Months.names[self.id]