Embedding Python in a shell script

Chris Angelico rosuav at gmail.com
Thu Jun 16 21:05:46 EDT 2011


On Fri, Jun 17, 2011 at 10:57 AM, Jason Friedman <jason at powerpull.net> wrote:
> The code behaves as I expect and want, but the de-denting of the
> Python call is unattractive, especially unattractive the longer the
> Python call becomes.  I'd prefer something like:
>

#!/bin/bash
for i in 1 2 3 4; do
  python -c "if True:
      for j in range($i):
          print j
  "
done

Untested, but it's a hack I've used in a few places. The if tells
Python to expect an indent, and nobody cares if your first indent is
two miles and the one after that is only another two spaces.

ChrisA



More information about the Python-list mailing list