syntax for -c cmd

Edward Elliott nobody at 127.0.0.1
Fri May 12 02:29:15 EDT 2006


Dennis Lee Bieber wrote:

> On Thu, 11 May 2006 20:12:55 GMT, Edward Elliott <nobody at 127.0.0.1>
> declaimed the following in comp.lang.python:
> 
>> 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:
>>
> More likely, the -C never processed anything after the first quoted
> statement.

Yep you are correct.  Odd, I could've sworn I've done that before.  Here's
what the man page has to say:

"when called with -c command, it executes the Python statement(s) given as
command.  Here command may contain  multiple  statements  separated by
newlines. ... following options are passed as arguments to the command."

So the following works:
$ python -c 'if 0 == 1: print "foo"  # arg is unterminated
$$ else: print "bar"'  # now we close it
bar

-- 
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net



More information about the Python-list mailing list