-c input

Mike Maxwell maxwell at ldc.upenn.edu
Tue Aug 31 15:51:21 EDT 2004


python -c "print 'hi'; for i in [1,2]: print i"

gives me an invalid syntax error, with the carat pointing to the end
of the word 'for'.  But

   python -c "print 'hi'; print 'i'"

works fine, as does 

   python -c "for i in [1,2]: print i"

What gives?  Why can't 'for' appear after a semicolon?  (Similar for
'while'.)

If there's some reason the 'for' can't be made to work after the
semicolon, is there some simple way to get a newline into the string
on the cmd line?  (short of using 'echo' twice, or putting the
commands into a file)

(I've tested this in v2.3.3 under both CygWin and Linux.)



More information about the Python-list mailing list