如果在python中块,无法有条件执行



我正在分配系统环境变量的值。基于此变量的值 - 是或错误,我有要执行的IF和其他块。当该变量的值为false时,它将成功执行Else块,但是如果变量的值为真,则它不会在IF块中执行语句。

代码片段是:

propDictionary = globals()
isMtEnabled = propDictionary['convertToMt']
 if isMtEnabled == "true" :
                if props.getProperty("ClusterName") != None and props.getProperty("ClusterName") != "" :
                        print "Have a cluster"
                        clusterNames = clusterName1.split()
                        print "clusterNames is "
                        print clusterNames
                        targetMBeans = []
                        for clusterName in clusterNames:
                                storeName='WseeFileStore_'+clusterName
                                addNamedFileStoreOnServer (storeName,clusterName,distPolicy="Distributed")
 else :
                counter = 0
                c1_arr = []
                c2_arr = []
                for serverName in serverList:
                        if serverName.startswith("c1"):
                                storeName='WseeFileStore_'+serverName
                                addNamedFileStoreOnServer(storeName,serverName,distPolicy="Distributed")
                                jmsServer = addJMSServer(serverName,storeName=storeName)

当我打印ISMTENABLED变量时,它将打印为True或false。当其值为真时,它应该执行IF块,而根本不输入IF块。

在这种情况下可能有什么问题?

您可以打印type(isMtEnabled)吗?如果结果是布尔值,请替换您的if:

if isMtEnabled :
  (... body ...)

最新更新