无法在Python中有条件地执行if块

2024-09-28 22:01:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为系统环境变量赋值。基于这个变量的值-true或false,我有了要执行的if和else块。 当该变量的值为false时,它将成功执行else块,但如果该变量的值为true,则它不会执行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。 当它的值为true时,它应该执行if块,而不是完全不进入if块。你知道吗

在这种情况下可能有什么问题?你知道吗


Tags: falsetrueforifpropselseprintservername