commands = ['chat', 'call', 'exit', 'friends', 'status']
class MainHub(object):
def menu(self):
while True:
selection = raw_input("> ")
if selection != any(commands):
print "Not a recognized command!\n"
else:
print selection
it prints “Not a recognized command!” everytime, even if selection is something like ‘chat’ or ‘call’. It’s a very simple snippet of code, but I just can’t seem to see what’s wrong with it!
You don’t want the
anyfunction, you want thenot insyntax:anyis from predicate calculus and checks whether any of its inputs areTrue. In this case, you’re comparing your input toany(commands), which isTruesince there is aTrueelement incommands.