Python: convention for a date without any year

I have a script that loops through a list of birthdays and then calculates the age. Some birthdays have a year, month, day, and some only have a month, day.

For those who have years, I have dob = date(year, month, day)

But for those who don't have years, what is the appropriate convention for storing a date, since the date()

year argument is required?

Now I say that everyone who was not born was born in 1500 (so I can at least identify them later), but this is obviously a stupid decision.

+3


source to share


1 answer


If not year

; don't use the class datetime.date

. date

must have year

. Either compute the field date

on the fly whenever you need it, if present year

, and / or create a property self.date

on your custom object to throw an error if used for an object without a year.



+1


source







All Articles