Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7814
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | mg <marco.giusti@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Embedding Python in a shell script |
| Date | Fri, 17 Jun 2011 08:58:37 +0000 (UTC) |
| Organization | Aioe.org NNTP Server |
| Lines | 45 |
| Message-ID | <itf4vt$ki1$1@speranza.aioe.org> (permalink) |
| References | <BANLkTimB7ygPz6YhxSzJWuAf_yGaW-Hdww@mail.gmail.com> <mailman.54.1308272749.1164.python-list@python.org> <3206787a-4feb-4098-8ed3-9e0b86ee7b57@o10g2000prn.googlegroups.com> |
| NNTP-Posting-Host | l5NyLaDLfqw4AdEKvc4N1A.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-15 |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | tin/1.9.6-20100522 ("Lochruan") (UNIX) (Linux/2.6.39 (x86_64)) |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7814 |
Show key headers only | View raw
rusi <rustompmody@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Embedding Python in a shell script Chris Angelico <rosuav@gmail.com> - 2011-06-17 11:05 +1000
Re: Embedding Python in a shell script rusi <rustompmody@gmail.com> - 2011-06-16 19:25 -0700
Re: Embedding Python in a shell script mg <marco.giusti@gmail.com> - 2011-06-17 08:58 +0000
csiph-web