Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'problem:': 0.07; 'welcome.': 0.07; "'python": 0.09; 'root,': 0.09; 'translate': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'files)': 0.16; 'syntax,': 0.16; 'subject:python': 0.16; 'thursday,': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; '(not': 0.18; 'app': 0.19; 'import': 0.22; 'email addr:gmail.com>': 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; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'lines': 0.31; "skip:' 10": 0.31; 'though.': 0.31; 'critical': 0.32; 'maybe': 0.34; 'subject:with': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'html,': 0.36; 'virtual': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'gmail': 0.38; 'files': 0.38; 'little': 0.38; 'skip:p 20': 0.39; 'great': 0.65; 'obvious': 0.74; '2014,': 0.84; 'ipad,': 0.84; 'subject:commands': 0.84; 'this...': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:cc:content-type; bh=RRpPvuZcKc8CWehlTZlIdry8kd16T+NRkXlVwbixdZs=; b=pQh0kBcrcd0fhNsQqdp8eVcW0WaprwSxKaLD5jAIWRvyjLA03YUkMhJjMcAsFaD87D 3B2rhp++j/b/98qvOV+EOkmpAbBwSsW9f533THxfqO0Q3bAADUhdiV/R2r42KzeLPxj3 5D4LDgWQLRhoK1Kafh7qg85pm0ZCoAmDcJ8GIkh8YHQ5T1rEvcFB7jY/KT3r+yPEn6CS OL8EIK/87hGt1hhNUik0rAqX3gu6CUi/7LNe8WIaHzCiO6yHnV+crDcgAqcWc/BbgTbq k8ABLUleQ0iouEwOhgojOz9Jeh+naZAcfvuDQXObuREn7/ZLNLkwYeGpKkLCpR8t7yeD MvUA== MIME-Version: 1.0 X-Received: by 10.42.211.205 with SMTP id gp13mr11345089icb.29.1401417299908; Thu, 29 May 2014 19:34:59 -0700 (PDT) Sender: zachary.ware@gmail.com In-Reply-To: References: Date: Thu, 29 May 2014 21:34:59 -0500 X-Google-Sender-Auth: noYH0mjJPBWa-js6yp111qcsGmY Subject: Multi-line commands with 'python -c' From: Zachary Ware Cc: "python-list@python.org" Content-Type: multipart/alternative; boundary=20cf301d39fc57dc5e04fa94e4e5 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: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401417303 news.xs4all.nl 2902 [2001:888:2000:d::a6]:44433 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72273 --20cf301d39fc57dc5e04fa94e4e5 Content-Type: text/plain; charset=UTF-8 On Thursday, May 29, 2014, Chris Angelico > wrote: > Since lines are so critical to Python syntax, I'm a little surprised > there's no majorly obvious solution to this... or maybe I'm just > blind. > > Problem: Translate this into a shell one-liner: > > import os > for root, dirs, files in os.walk("."): > if len(dirs + files) == 1: print(root) > > Is there a better way to put multiple virtual lines into a 'python -c' > command? > You can always cheat: $ python -c 'exec("import os\nfor root, dirs, files in os.walk(\".\"):\n if len(dirs + files) == 1: print(root)")' Doesn't do much for being long and fiddly, though. -- Zach Sent from an iPad, please bear with any brevity, uncaught auto-uncorrections, HTML, or other annoyances. Suggestions for a great (not just 'good') email app are welcome. -- Sent from Gmail Mobile --20cf301d39fc57dc5e04fa94e4e5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thursday, May 29, 2014, Chris Angelico <rosuav@gm= ail.com> wrote:
Since lines are so critical to Python syntax, I'm a little surprised there's no majorly obvious solution to this... or maybe I'm just blind.

Problem: Translate this into a shell one-liner:

import os
for root, dirs, files in os.walk("."):
=C2=A0 =C2=A0 if len(dirs + files) =3D=3D 1: print(root)
&= lt;snip>=C2=A0

Is there a better way to put multiple virtual lines into a 'python -c&#= 39; command?

You can always cheat:

=
$ python -c 'exec("import os\nfor root, dirs, files in os.wal= k(\".\"):\n if len(dirs + files) =3D=3D 1: print(root)")'= ;

Doesn't do much for being long and fiddly, though.<= /div>

--
Zach

Sent fr= om an iPad, please bear with any=C2=A0brevity, uncaught auto-uncorrections,= HTML, or other annoyances. Suggestions for a great (not just 'good'= ;)=C2=A0email app are welcome.


--
Sent from Gmail Mobile
--20cf301d39fc57dc5e04fa94e4e5--