I have a dictionary of methods in Python that is inside of a definition. This def is called outside of the class using an object. Whenever the def is called I am returned the results of the last item in the dictionary. In this case I am returned the results of def spc_summary:.
def setStyles(self):
# Assign function to file
functions = {
'app_server.php':self.app_server(),
'dcrm2nlyte.php':self.dcrm2nlyte(),
'export.php':self.export(),
'host_server.php':self.host_server(),
'spc.php':self.spc(),
'spc_approved.php':self.spc_approved(),
'spc_approved_by_dc.php':self.spc_approved_by_dc(),
'spc_by_dc.php':self.spc_by_dc(),
'spc_complete.php':self.spc_complete(),
'spc_summary.php':self.spc_summary()
}
filename = self.phpfile
functions.get(filename)
Can someone please explain what is happening here? Let me know if more detail is required. Thanks!
Let me add some detail:
The functions.get(filename) is retreiving the last dictionary item reguardless of what filename is. I have done this => functions('spc.php') and it still returned results for `def spc_summary’. And those def’s should not have the same results.
Your function dict seems to be doing the wrong thing. While defining your dict you are mapping the keys to the function result instead of the function object. If you map it to the function object the function gets called when you invoke
functions.get(filename)()Your dict should probably be like below: