Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72320

Re: Multi-line commands with 'python -c'

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'problem:': 0.07; 'booth': 0.09; 'interpreted': 0.09; 'newline': 0.09; 'root,': 0.09; 'translate': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'windows': 0.15; 'files)': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'import': 0.22; 'shell': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'unix': 0.29; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'multiline': 0.31; 'linux': 0.33; 'url:python': 0.33; 'fri,': 0.33; 'subject:with': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'unit': 0.37; 'area': 0.37; 'skip:. 20': 0.38; 'files': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'easy': 0.60; 'new': 0.61; 'back': 0.62; '30,': 0.65; 'subject:commands': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=0rOu+uT6aqMKJJg+2iKnYABMgsVrc376m4KiXoGfgWQ=; b=t7uup8CeX19noA/S93ZkbyDR+DqALHiAQVdrb9UAb1tvjszKGLKbz09M/pE/c9uFRQ x1uoHzhTdcZ8IhLosCP+uFtviC1jp69HXy2TsH65SFYABoD4smm2Uxrcv16zkc5C3G+E A8o58VdP4haY4l2GXK9gehT0iSsoW4GyfVgE1HUoOA+51eO5iI1GR1pvWNXaTWDdIj/8 Vi5ngKrRXQPBeiQQCO6joayTzRXqV9QJgWm+z7ugT+cCel+on5Gr+RrnKz6nja6tz4Bp unJ8KGVvc+f0Bf2s/IOwrNPLDHDr/Zr7rjI6Y1T4H6fG2rTQiv7Aec6STsk9NFq5XbqN +uGg==
X-Received by 10.140.18.180 with SMTP id 49mr24120754qgf.105.1401486175226; Fri, 30 May 2014 14:42:55 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <XnsA33DE1B7E35C5duncanbooth@127.0.0.1>
References <mailman.10468.1401411146.18130.python-list@python.org> <XnsA33DE1B7E35C5duncanbooth@127.0.0.1>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Fri, 30 May 2014 14:42:15 -0700
Subject Re: Multi-line commands with 'python -c'
To duncan.booth@suttoncourtenay.org.uk
Content-Type text/plain; charset=UTF-8
Cc "comp.lang.python" <python-list@python.org>
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.10498.1401486177.18130.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401486177 news.xs4all.nl 2964 [2001:888:2000:d::a6]:35528
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72320

Show key headers only | View raw


In unix shells you can literally use a new line. Or is that only bash?

-- Devin

On Fri, May 30, 2014 at 2:11 PM, Duncan Booth
<duncan.booth@invalid.invalid> wrote:
> Chris Angelico <rosuav@gmail.com> wrote:
>
>> Problem: Translate this into a shell one-liner:
>>
>> import os
>> for root, dirs, files in os.walk("."):
>>     if len(dirs + files) == 1: print(root)
>>
>
> This is one area where Windows seems to do better than Linux shells:
>
> PS C:\python33> python -c "import os`nfor root, dirs, files in os.walk('.'):`n    if len(dirs + files) == 1: print(root)`n"
> .\Doc
> .\Lib\concurrent\__pycache__
> .\Lib\curses\__pycache__
> ...
>
> The `n shell escaped newline is interpreted well before Python runs.
>
> Also the multiline version works and in Powershell ISE up-arrow pulls it back as a
> single unit for easy editing:
>
> PS C:\python33> python -c @"
> import os
> for root, dirs, files in os.walk('.'):
>     if len(dirs + files) == 1: print(root)
> "@
> .\Doc
> .\Lib\concurrent\__pycache__
> .\Lib\curses\__pycache__
> ... and so on ...
>
>
> --
> Duncan Booth
> --
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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