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


Groups > comp.lang.python > #72273

Multi-line commands with 'python -c'

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 <zachary.ware@gmail.com>
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&gt;': 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 <CAPTjJmoGTu4s0+rwfGVjnfeFfqxOzQGevtL8vsxULBm=Ff+Ouw@mail.gmail.com>
References <CAPTjJmoGTu4s0+rwfGVjnfeFfqxOzQGevtL8vsxULBm=Ff+Ouw@mail.gmail.com>
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 <zachary.ware+pylist@gmail.com>
Cc "python-list@python.org" <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 <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.10471.1401417303.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Thursday, May 29, 2014, Chris Angelico <rosuav@gmail.com
<javascript:_e(%7B%7D,'cvml','rosuav@gmail.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("."):
>     if len(dirs + files) == 1: print(root)

<snip>

>
> 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

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


Thread

Multi-line commands with 'python -c' Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-05-29 21:34 -0500

csiph-web