how to simplify boolean logic in if else statement?

前端 未结 2 1716
一生所求
一生所求 2021-01-17 03:01

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 ea

2条回答
  •  再見小時候
    2021-01-17 03:16

    One way to simplify it would be to recognise and factor out the duplication:

    if self.phone:
        if self.isp() == "east":
            self.launchbell()
        else:
            self.launchtelus()
    
    if self.cpe_ip and 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()
    

提交回复
热议问题