do python's nifty indentation rules spell the death of one-liners?

Gerhard Häring gh at ghaering.de
Tue Apr 15 20:25:32 EDT 2003


* Dan Jacobson <jidanni at dman.ddts.net> [2003-04-15 13:59 +0800]:
> I need to use one liners every day, especially in Makefiles.  I thus
> need to know how to make any kind of python program into a big long one
> liner. However, right out of the starting gates I run into
> $ python -c 'print 2;for i in (1,4):print i'
>   File "<string>", line 1
>     print 2;for i in (1,4):print i
>               ^
> SyntaxError: invalid syntax

Try:

python -c """
print 2
for i in (1, 4):
    print i
"""

It seems to work under a bash script at least. I once did something with
<<EOF but have since forgotten the little knowledge I had a about shell
scripting ;-)

> [...] If I found a bug, report it for me.

If you really find a bug *you* can report it with the Python bug tracker
at Sourceforge.

Gerhard
-- 
mail:   gh at ghaering.de
web:    http://ghaering.de/





More information about the Python-list mailing list