I am writing a function which takes in an object of a class, e.g. Transaction, that has two attributes "date1" and "date2", which in turn are both classes that have three attributes "day", "month", and "year".I will pass this function an object of the class Transaction as well as whether I am analyzing "date1" or "date2". So the function will look something like:
def analyzeTransaction(txObject, date='date1'):
txObject.{date}.year()
Where {date} can either can referring to the date1 or date2 member depending on argument passed.
I know how to do this using getattr(), but I was hoping for a more elegant solution since I find using getattr() everywhere to be clunky.