python - how to simplify boolean logic in if else statement? -


i have 4 variables, of them true , false, , each combinations, have call 1 or few functions. using if else statement each case , know if there nicer way same result dictionary or else.

thank you

here code :

    if (self.cpe_ip , self.cpe_passwd) , self.phone , self.pppoe:         print "launch isp portal, modem , 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 , self.cpe_passwd) , not self.phone , not self.pppoe:         print "launch modem test only"         self.modemstatus()           #exit(0)     elif not(self.cpe_ip , self.cpe_passwd) , self.phone , not self.pppoe:         #print "only  bell portal"         if self.isp() == "east":             self.launchbell()         else:             self.launchtelus()      elif (self.cpe_ip , self.cpe_passwd) , not self.phone , self.pppoe:         #print "launch modem , 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 , self.cpe_passwd) , not self.phone , self.pppoe:         #print "only radius tests."         radius = sgp_radius.radius(self.pppoe)         self.data = radius.sgp()          self.radius_save()      elif not(self.cpe_ip , self.cpe_passwd) , self.phone , self.pppoe:         print "bell , 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 , self.cpe_passwd) , self.phone , not self.pppoe:         #print "launch modem , bell tests."         if self.isp() == "east":             self.launchbell()         else:             self.launchtelus()         self.modemstatus()      else:         #print "test bell only"         #launchbell(self.phone)         exit(0) 

one way simplify recognise , factor out duplication:

if self.phone:     if self.isp() == "east":         self.launchbell()     else:         self.launchtelus()  if self.cpe_ip , self.cpe_passwd:     print 'check modem...'     self.modemstatus()  if self.pppoe:     radius = sgp_radius.radius(self.pppoe)     print 'check radius logs...'     self.data = radius.sgp()     self.radius_save() 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -