Reputation: 133
I'm using argparse.
def help():
parser.print_help()
sys.exit(0)
help() if (args.lock and args.unlock)
This gives me a syntax error. What is wrong with my if statement?
Upvotes: 12
Views: 9267
Reputation: 1122342
You are using a conditional expression: true_result if condition else false_result
. A conditional expression requires an else
part, because it has to produce a value; i.e. when the condition is false, there has to be an expression to produce the result in that case.
Don't use a conditional expression when all you want is a proper if
statement:
if args.lock and args.unlock: help()
Upvotes: 15