I know that I can’t overload functions in python, and I can’t seem to get my head around using python to get the behavior I’m after.
An Example:
class Hop(object):
def __init__(self, variety, aa, qty, time):
self.variety = variety
self.aa = aa
self.qty = qty
self.time = time
class HopBill(object):
hop_list = []
def add(self, hop):
self.hop_list.append(hop)
# Where I would put an overloaded function?
def add(self, variety, aa, qty, time):
self.hop_list.append(Hop(variety, aa, qty, time))
I’m not really crazy about just using kwds and just adding a bunch of logic to decode what inputs my function received.
I’m getting the feeling there is a way better way of setting this up, anyone have any advice on how to take a more pythonic approach?
Thanks!
Just make two methods. Init hop_list in __init__ or the instances of HopBill will share the list: