0

I've been trying to build a function to interpret command-line inputs, then runs the appropriate function from within the script file with provided arguments. Included in this function is a escape command that closes the interaction layer. This escape command should only be activated if the user enters either 'exit' or 'end'. However, for some reason, it triggers no matter what is entered. I'm stumped. Do any of you have an idea?

verinfo ()
x = True
while x is True:
    print ('Please seperate arguments with a comma.')
    inputstring = input('->')
    #format input string to a standard configuration
    #expected is command,arg1,arg2,arg3,arg4,arg5
    procstring = inputstring.split (',')
    while len(procstring) < 6:
        procstring.append('')
        print (procstring)
    #escape clause
    print (procstring[0])
    if procstring[0] is 'end' or 'exit':
        print ('Closing')
        x = False
        break
    elif procstring[0] is 'help' or 'Help':
        Help ()

    else:
        print ('command invalid. List of commands can be accessed with "help"')
Rycoba
  • 3
  • 1
  • Comparison should be `if procstring[0] in ('end', 'exit'): ...` OR `if procstring[0] == 'end' or procstring[0] == 'exit': ...` – zamir Feb 04 '20 at 12:06
  • There are two problems here; both are common FAQs. Read both duplicates. – tripleee Feb 04 '20 at 12:30

2 Answers2

0

Such comparisons you should do with the == operator, for example:

if procstring[0] == 'end' or procstring[0] == 'exit':
    print(...)
0

So here are two different concepts, one being identity and the other equality.

So the keyword is is not testing for equality but for identity. Meaning... are these two objects the same? take a look at id().

I think you can take a look at a lot of pages trying to explain the difference between == and is.

Raserhin
  • 2,516
  • 1
  • 10
  • 14