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

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Wed Apr 16 00:18:01 EDT 2003


I wrote:
> I just tried this in a Makefile, and it seems to work:
> 
> all:
>     python -c '\
>     for i in range(10):\
>      print i'

Oops, looks like I spoke too soon, because this
*doesn't* work:

all:
	python -c '\
	print "Hi"\
	for i in range(10):\
	  print i'

It seems that make puts the whole command on one line,
no matter how you lay it out in the Makefile. Bugger.

But do you really have to put the actual Python in
the Makefile? You could have a file full of Python
functions, one for each snippet, and call them
using things like:

   python -c 'import stuff; stuff.spam()'

I just tested that in the Makefile, and it
*does* work!

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list