Syntax error [was: Installed modules list?]

Steven D. Majewski sdm7g at Virginia.EDU
Fri Apr 20 11:58:19 EDT 2001


On Tue, 17 Apr 2001, John J. Lee wrote:

> I was going to suggest a find command, if you're on unix, but then I
> discovered I didn't understand python syntax:
> 
> $ echo `python -c 'for d in [1,2]: print d'`
> 
> works, while
> 
> $ echo `python -c 'import sys; for d in [1,2]: print d'`
> 
> doesn't -- it's a SyntaxError.
> 
> Why?
> 

Interesting.

Also:

	>>> print 1; print 2; if [1]: print 3
	  File "<stdin>", line 1
	    print 1; print 2; if [1]: print 3
        	               ^
	SyntaxError: invalid syntax


I haven't looked at the actual grammar in quite a while, but I'm
guessing that there is a bit of an overgeneralization in the rules
to prevent compound statements like: 

	>>> for x in [1,0,2]: if x : print x 
	  File "<stdin>", line 1
	    for x in [1,0,2]: if x : print x
                       ^
	SyntaxError: invalid syntax


which are definitely disallowed. 

-- Steve Majewski





More information about the Python-list mailing list