Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72273
| References | <CAPTjJmoGTu4s0+rwfGVjnfeFfqxOzQGevtL8vsxULBm=Ff+Ouw@mail.gmail.com> |
|---|---|
| Date | 2014-05-29 21:34 -0500 |
| Subject | Multi-line commands with 'python -c' |
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10471.1401417303.18130.python-list@python.org> (permalink) |
[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
Multi-line commands with 'python -c' Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-05-29 21:34 -0500
csiph-web