I have 4 variables, some of them will be True and False, and for each combinations, i will have to call one or few functions. i am currently using a if else statement for each case and i would like to know if there is a nicer way to get the same result with a dictionary or something else.
Thank you
here is my code :
if (self.cpe_ip and self.cpe_passwd) and self.phone and self.pppoe: print "launch ISP portal, modem and radius" if self.isp() == "east": self.launchbell() else: self.launchtelus() print 'check modem...' self.modemstatus() radius = sgp_radius.Radius(self.pppoe) print 'check radius logs...' self.data = radius.sgp() self.radius_save() #exit(0) elif (self.cpe_ip and self.cpe_passwd) and not self.phone and not self.pppoe: print "launch modem test only" self.modemstatus() #exit(0) elif not(self.cpe_ip and self.cpe_passwd) and self.phone and not self.pppoe: #print "only Bell portal" if self.isp() == "east": self.launchbell() else: self.launchtelus() elif (self.cpe_ip and self.cpe_passwd) and not self.phone and self.pppoe: #print "launch modem and radius test." self.modemstatus() radius = sgp_radius.Radius(self.pppoe) print 'check radius logs...' self.data = radius.sgp() self.radius_save() elif not(self.cpe_ip and self.cpe_passwd) and not self.phone and self.pppoe: #print "only radius tests." radius = sgp_radius.Radius(self.pppoe) self.data = radius.sgp() self.radius_save() elif not(self.cpe_ip and self.cpe_passwd) and self.phone and self.pppoe: print "bell and radius tests." if self.isp() == "east": self.launchbell() else: self.launchtelus() radius = sgp_radius.Radius(self.pppoe) print 'check radius logs...' self.data = radius.sgp() self.radius_save() elif (self.cpe_ip and self.cpe_passwd) and self.phone and not self.pppoe: #print "launch modem and bell tests." if self.isp() == "east": self.launchbell() else: self.launchtelus() self.modemstatus() else: #print "test bell only" #launchbell(self.phone) exit(0)