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


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

Re: Multi-line commands with 'python -c'

Started byChris Angelico <rosuav@gmail.com>
First post2014-05-30 12:47 +1000
Last post2014-05-30 12:47 +1000
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

  Re: Multi-line commands with 'python -c' Chris Angelico <rosuav@gmail.com> - 2014-05-30 12:47 +1000

#72275 — Re: Multi-line commands with 'python -c'

FromChris Angelico <rosuav@gmail.com>
Date2014-05-30 12:47 +1000
SubjectRe: Multi-line commands with 'python -c'
Message-ID<mailman.10473.1401418078.18130.python-list@python.org>
On Fri, May 30, 2014 at 12:34 PM, Zachary Ware
<zachary.ware+pylist@gmail.com> wrote:
> 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.

Not really, no! Heh. I wrote that in competition against a theoretical
solution involving shell commands and pipes and so on, with the
intention being that the Python version could be a simple shell
one-liner, just as the pipe version could. (The task: Find all
directories with exactly one subdirectory or file in them, not
counting dot and dot-dot. Python's os.walk() is pretty much perfect
for that.) I tried fiddling with __import__() rather than the import
statement, but it didn't really aid clarity much.

ChrisA

[toc] | [standalone]


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


csiph-web