I'm trying to make a call to several functions dinamically. I can do it if this methods are publics but when I make this methods private doesn't work the same code.
I'm trying to call these functions dinamically:
def __total_voucher(self, quantity):
return quantity
def __total_tshirt(self, quantity):
return quantity
def __total_mug(self, quantity):
return quantity
And the method from where I try to make a call dynamically to that methods are:
def total(self):
total = 0
for item in self.list_products:
function = "__total_%s" % item.lower()
if item in self.cart:
total += getattr(self, function)(self.cart[item])
return total
When I run the method "total" I've got this error:
File "/home/josecarlos/Workspace/python/CofiCodeChallenge/checkout.py", line 56, in total
total += getattr(self, function)(self.cart[item])
AttributeError: 'CheckOut' object has no attribute '__total_voucher'
What am I doing wrong? How can I make a call to private functions in Python?