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


Groups > comp.lang.python > #72273 > unrolled thread

Multi-line commands with 'python -c'

Started byZachary Ware <zachary.ware+pylist@gmail.com>
First post2014-05-29 21:34 -0500
Last post2014-05-29 21:34 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#72273 — Multi-line commands with 'python -c'

FromZachary Ware <zachary.ware+pylist@gmail.com>
Date2014-05-29 21:34 -0500
SubjectMulti-line commands with 'python -c'
Message-ID<mailman.10471.1401417303.18130.python-list@python.org>

[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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web