rusi <rustompm...@gmail.com> wrote:
> On Jun 17, 6:05 am, Chris Angelico <ros...@gmail.com> wrote:
> 
>> > Python call becomes.  I'd prefer something like:
>>
>> #!/bin/bash
>> for i in 1 2 3 4; do
>>   python -c "if True:
> # comfortably indented python code
> 
> Thanks. Nice!

You can use bash here document feature, <<-, that strips heading tab
characters but not spaces.


        #!/bin/bash

        for i in 1 2 3 4; do
                python /dev/stdin <<-EOF
                        for i in range($i):
                            print i # two tabs and four spaces
                        EOF
        done

Or alternatively you can use a temporary file:


        #!/bin/bash

        TEMPFILE=$(mktemp)
        trap 'rm -f $TEMPFILE' TERM INT

        cat > $TEMPFILE <<EOF
        import sys

        for i in range(int(sys.argv[1])):
            print i
        EOF

        for i in 1 2 3 4; do
                python $TEMPFILE $i
        done


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to