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

Grant Edwards grante at visi.com
Thu Apr 17 11:18:31 EDT 2003


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?

-- 
Grant Edwards                   grante             Yow!  While I'm in
                                  at               LEVITTOWN I thought I'd
                               visi.com            like to see the NUCLEAR
                                                   FAMILY!!




More information about the Python-list mailing list