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

Steve Holden sholden at holdenweb.com
Thu Apr 17 11:22:18 EDT 2003


"Grant Edwards" <grante at visi.com> wrote in message
news:3e9ec5c7$0$178$a1866201 at newsreader.visi.com...
> In article <dSxna.114901$It5.77194 at news2.central.cox.net>, Steve Holden
wrote:
> > "Grant Edwards" <grante at visi.com> wrote in message
> > news:3e9dca74$0$170$a1866201 at newsreader.visi.com...
> >> In article <a8b7f07a.0304161314.361a80fa at posting.google.com>, A. Lloyd
> > Flanagan wrote:
> >>
> >> >> > python << DONE
> >> >> > print 2
> >> >> > for i in (1,4):
> >> >> >      print i
> >> >> > DONE
> >> >>
> >> >> But how do you do it in a Makefile?
> >> >
> >> > Err.  Put it in a script file, and call the script file from make?
> >>
> >> That's one solution, but now you've got another file to keep
> >> track of.
> >>
> >> > I tried sticking it in a Makefile, can't get it to work.  So far.
> >>
> >> How 'bout this:
> >>
> >> all:
> >>         python2 -c $$'for i in range(5):\n print i\n\n'
> >>
> >>
> >> I think that the $'<string>' notation is a bash-ism.  If that's
> >> a problem, then
> >>
> >>         echo -e "for i in range(5):\n print i\n\n" | python2
> >>
> >> should also work.  Adjust the echo options appropriately to get
> >> interpretation of \n to work.
> >>
> >> There may be other ways to get Make to interpret \n in a
> >> string...
> >>
> > Now try putting an import before the "for" statement ...
>
> OK...
>
>   echo -e 'import sys\nfor i in range(5):\n
sys.stdout.write(str(i)+"\\n")\n\n' | python2
>
> Works for me.  Was it supposed to fail?
>

We=ll, you might say I was just too lazy to test it for myself :-)

regards
--
Steve Holden                                  http://www.holdenweb.com/
How lucky am I?      http://www.google.com/search?q=Steve+Holden&btnI=1
Python Web Programming                 http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list