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

Dan Jacobson jidanni at dman.ddts.net
Tue Apr 15 01:59:54 EDT 2003


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

Help. BTW tell me what to do in all the other cases when ";" can't be
a replacement for newline.  I.e. does python's nifty indentation rules
spell the death of one-liners?

BTW, how do I import a module from the command line when using -c? Is
there an option switch for importing modules?

This makes no output and returns no error value to the shell:
$ python -c 'import math' -c 'for i in range(200,500,50): print
  i,360/2/math.pi*math.asin(i/1238.4)'

If I found a bug, report it for me.
-- 
http://jidanni.org/ Taiwan(04)25854780




More information about the Python-list mailing list