Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72343
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '"this': 0.03; '(at': 0.04; 'syntax': 0.04; 'model,': 0.05; 'python3': 0.07; 'bash': 0.09; 'booth': 0.09; 'difference,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'root,': 0.09; 'statements': 0.09; 'python': 0.11; 'wrote': 0.14; 'windows': 0.15; "'for',": 0.16; "'if',": 0.16; "'in',": 0.16; 'argument.': 0.16; 'bash,': 0.16; 'cleaner': 0.16; 'files)': 0.16; 'it;': 0.16; 'line)': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'syntaxerror:': 0.16; 'subject:python': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'file,': 0.19; 'command': 0.22; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; '31,': 0.24; 'simpler': 0.24; "i've": 0.25; 'script': 0.25; 'this:': 0.26; 'least': 0.26; 'primary': 0.26; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'unix': 0.29; 'related': 0.29; 'originally': 0.30; "skip:' 10": 0.31; '"",': 0.31; 'minor': 0.31; 'file': 0.32; 'running': 0.33; 'style': 0.33; 'actual': 0.34; 'subject:with': 0.35; 'point.': 0.35; 'but': 0.35; 'useful': 0.36; 'skip:. 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'commands': 0.60; 'new': 0.61; 'more': 0.64; 'series': 0.66; 'direct': 0.67; 'importantly,': 0.68; 'invalid': 0.68; 'lack': 0.78; 'repeat.': 0.84; 'subject:commands': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Multi-line commands with 'python -c' |
| Date | Sat, 31 May 2014 19:11:03 +0200 |
| Organization | None |
| References | <mailman.10468.1401411146.18130.python-list@python.org> <XnsA33DE1B7E35C5duncanbooth@127.0.0.1> <CABicbJKjGCoEuZpAXfr_YUzFD=BYq_ezjkSf57k4vRjnb3MhvA@mail.gmail.com> <mailman.10500.1401486463.18130.python-list@python.org> <XnsA33EAA18C31A6duncanbooth@127.0.0.1> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bdb5da.dip0.t-ipconnect.de |
| User-Agent | KNode/4.11.5 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10511.1401556283.18130.python-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1401556283 news.xs4all.nl 2837 [2001:888:2000:d::a6]:56421 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:72343 |
Show key headers only | View raw
Duncan Booth wrote:
> Chris Angelico <rosuav@gmail.com> wrote:
>
>> On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre
>><jeanpierreda@gmail.com> wrote:
>>> In unix shells you can literally use a new line. Or is that only
> bash?
>>
>> You can in bash, I know, but it's fiddly to type it; and more
>> importantly, it's not a good point in the "this is cleaner than a
>> series of pipes" argument. My primary recommendation, of course, was a
>> three-line script saved as an actual file, but for a more direct
>> parallel to the pipe-it-three-ways model, I wanted to use -c.
>
> and you also wrote originally that it's fiddly to edit. I think that
> Windows Powershell has (at least in the current ISE command line) got
> the editing a bit better. It's a minor difference though and it has
> taken Microsoft about 30 years to get to that point.
>
> What may be a larger difference, or may just be my lack of Linux-foo, is
> this:
>
> PS C:\python33> $script = @"
> import os
> for root, dirs, files in os.walk("."):
> if len(dirs + files) == 1: print(root)
> "@
>
> PS C:\python33> python -c $script
> .\Doc
> .\Lib\concurrent\__pycache__
> .\Lib\curses\__pycache__
> ...
>
> which is a style I've found useful for example when running a group of
> related timeit.py commands as I can put things like multi-line setup
> statements in a variable and then have a simpler command to repeat.
>
> But bash as far as I can won't let me do that:
>
> $ script='import os
> for root, dirs, files in os.walk("."):
> if len(dirs + files) == 1: print(root)
> '
> $ python -c $script
> File "<string>", line 1
> import
> ^
> SyntaxError: invalid syntax
$ script='import os
> for root, dirs, files in os.walk("."):
> if len(dirs + files) == 1:
> print(root)
> '
$ python3 -c "$script"
.
./heureka
$ python3 -c 'import sys; print(sys.argv)' $script
['-c', 'import', 'os', 'for', 'root,', 'dirs,', 'files', 'in',
'os.walk("."):', 'if', 'len(dirs', '+', 'files)', '==', '1:', 'print(root)']
$ python3 -c 'import sys; print(sys.argv)' "$script"
['-c', 'import os\nfor root, dirs, files in os.walk("."):\n if len(dirs +
files) == 1:\n print(root)\n']
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 10:52 +1000
Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:04 -0700
Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:45 -0700
Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-29 23:54 -0700
Re: Multi-line commands with 'python -c' Peter Otten <__peter__@web.de> - 2014-05-30 09:33 +0200
Re: Multi-line commands with 'python -c' Terry Reedy <tjreedy@udel.edu> - 2014-05-30 11:29 -0400
Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 17:20 +1000
Re: Multi-line commands with 'python -c' Rustom Mody <rustompmody@gmail.com> - 2014-05-30 05:47 -0700
Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 22:58 +1000
Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-05-30 21:11 +0000
Re: Multi-line commands with 'python -c' Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 14:42 -0700
Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-31 07:47 +1000
Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-05-31 16:41 +0000
Re: Multi-line commands with 'python -c' Peter Otten <__peter__@web.de> - 2014-05-31 19:11 +0200
Re: Multi-line commands with 'python -c' Duncan Booth <duncan.booth@invalid.invalid> - 2014-06-01 20:43 +0000
csiph-web