jeudi 11 avril 2019

if clause is not catching the case even though identical strings are compared

In the code below I am trying to enter a if/elif-clause when the compared string is equal to the string/s in the if-statement but the program does not seem to catch the cases.

I have tried printing the variables to see what they contain when I run the code and the printed result is the following:

commandType in Process: C_PUSH
commandType in Process: C_PUSH
commandType in Process: C_ARITHMETIC

The code (in python 2) that I am running is the following:

while parser.Advance():

    commandType = parser.CommandType()
    print "commandType in Process:", commandType
    if commandType == C_ARITHMETIC:
        print("commandType is C_ARITHMETIC")
        codeWriter.WriteArithmetic(parser.Arg1())
    elif commandType in (C_PUSH, C_POP):
        print("commandType is C_PUSH OR C_POP")
        codeWriter.WritePushPop(commandType, parser.Arg1(), parser.Arg2())

So the expected result should be that it prints something like:

commandType in Process: C_PUSH
commandType is C_PUSH OR C_POP
commandType in Process: C_PUSH
commandType is C_PUSH OR C_POP
commandType in Process: C_ARITHMETIC
commandType is C_ARITHMETIC

"Process" is just the name of the function that this block is found in.

Aucun commentaire:

Enregistrer un commentaire