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: 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: References: From: Devin Jeanpierre 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" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 wrote: > Chris Angelico 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