Multi-line commands with 'python -c'

Devin Jeanpierre jeanpierreda at gmail.com
Fri May 30 17:42:15 EDT 2014


In unix shells you can literally use a new line. Or is that only bash?

-- Devin

On Fri, May 30, 2014 at 2:11 PM, Duncan Booth
<duncan.booth at invalid.invalid> wrote:
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> Problem: Translate this into a shell one-liner:
>>
>> import os
>> for root, dirs, files in os.walk("."):
>>     if len(dirs + files) == 1: print(root)
>>
>
> This is one area where Windows seems to do better than Linux shells:
>
> PS C:\python33> python -c "import os`nfor root, dirs, files in os.walk('.'):`n    if len(dirs + files) == 1: print(root)`n"
> .\Doc
> .\Lib\concurrent\__pycache__
> .\Lib\curses\__pycache__
> ...
>
> The `n shell escaped newline is interpreted well before Python runs.
>
> Also the multiline version works and in Powershell ISE up-arrow pulls it back as a
> single unit for easy editing:
>
> PS C:\python33> python -c @"
> import os
> for root, dirs, files in os.walk('.'):
>     if len(dirs + files) == 1: print(root)
> "@
> .\Doc
> .\Lib\concurrent\__pycache__
> .\Lib\curses\__pycache__
> ... and so on ...
>
>
> --
> Duncan Booth
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list