do python's nifty indentation rules spell the death of one-liners?
peter at engcorp.com
Wed Apr 16 02:50:11 CEST 2003
Dan Jacobson wrote:
> 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 think you're looking for this (all on one line, with a space instead
of the line break):
C:\>python -c "exec '''import math\nfor i in range(200,500,50):\n print
More information about the Python-list