J
James
Wrong syntax is shown below. What should be the delimiter before else?
python -c 'if 1==1: print "yes"; else print "no"'
James
python -c 'if 1==1: print "yes"; else print "no"'
James
James said:Wrong syntax is shown below. What should be the delimiter before else?
python -c 'if 1==1: print "yes"; else print "no"'
there is no such delimiter. Python's syntax doesn't allow you to put multiple
clauses on a single line. if your shell supports it, use a "here document", or
embedded newlines. if not, use a script.
James said:Wrong syntax is shown below. What should be the delimiter before else?
python -c 'if 1==1: print "yes"; else print "no"'
James
James said:Wrong syntax is shown below. What should be the delimiter before else?
python -c 'if 1==1: print "yes"; else print "no"'
More likely, the -C never processed anything after the first quotedIf putting the else in a separate arg unbinds it from the if, I would expect
a syntax error. If OTOH naked elses are allowed on the command line for
some odd reason, then this shouldn't happen:
Dennis said:More likely, the -C never processed anything after the first quoted
statement.
Edward said:Now this is interesting. I broke the line up into separate arguments and it
seemed to work fine:
$ python -c 'if 1==1: print "yes"' 'else: print "no"'
yes
But then I tested the else branch and it produces no output:
$ python -c 'if 1==0: print "yes"' 'else: print "no"'
$
If putting the else in a separate arg unbinds it from the if, I would expect
a syntax error. If OTOH naked elses are allowed on the command line for
some odd reason, then this shouldn't happen:
$ python -c 'else: print "no"'
File "<string>", line 1
else: print "no"
^
SyntaxError: invalid syntax
What's with the silent failure in the two-arg version? If the else arg is
syntactically acceptable, why doesn't it behave as expected?
Fredrik said:hint:
$ python -c 'import sys; print sys.argv' 'else: print "no"'
</F>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.