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

2014-06-01 Thread Duncan Booth
Peter Otten <__pete...@web.de> wrote: > Duncan Booth wrote: > >> Chris Angelico wrote: >> >>> On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre >>> wrote: In unix shells you can literally use a new line. Or is that only >> bash? >>> >>> You can in bash, I know, but it's fiddly to type it;

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

2014-05-31 Thread Peter Otten
Duncan Booth wrote: > Chris Angelico wrote: > >> On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre >> wrote: >>> In unix shells you can literally use a new line. Or is that only > bash? >> >> You can in bash, I know, but it's fiddly to type it; and more >> importantly, it's not a good point in

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

2014-05-31 Thread Duncan Booth
Chris Angelico wrote: > On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre > wrote: >> In unix shells you can literally use a new line. Or is that only bash? > > You can in bash, I know, but it's fiddly to type it; and more > importantly, it's not a good point in the "this is cleaner than a > se

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

2014-05-30 Thread Chris Angelico
On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre wrote: > In unix shells you can literally use a new line. Or is that only bash? You can in bash, I know, but it's fiddly to type it; and more importantly, it's not a good point in the "this is cleaner than a series of pipes" argument. My primary r

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

2014-05-30 Thread Devin Jeanpierre
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 wrote: > Chris Angelico wrote: > >> Problem: Translate this into a shell one-liner: >> >> import os >> for root, dirs, files in os.walk("."): >> if len(dirs + files)

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

2014-05-30 Thread Duncan Booth
Chris Angelico 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, di

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

2014-05-30 Thread Terry Reedy
On 5/30/2014 2:45 AM, Rustom Mody wrote: $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in os.walk(".") if len(d+f) != 1])' Mysterious that print after a ; is fine whereas for is not Not at all. Simple statememts can follow ; or :, compound statements cannot. -- Terry Jan Re

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

2014-05-30 Thread Chris Angelico
On Fri, May 30, 2014 at 10:47 PM, Rustom Mody wrote: > On Friday, May 30, 2014 12:50:31 PM UTC+5:30, Chris Angelico wrote: >> On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: >> > I thought when one signs up for python one has to sign an affidavit >> > saying: >> > "I shall not write one-liners

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

2014-05-30 Thread Rustom Mody
On Friday, May 30, 2014 12:50:31 PM UTC+5:30, Chris Angelico wrote: > On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: > > I thought when one signs up for python one has to sign an affidavit > > saying: > > "I shall not write one-liners\n" * 100 > Certainly not. I write all my list comps on one

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

2014-05-30 Thread Peter Otten
Rustom Mody wrote: > On Friday, May 30, 2014 12:15:46 PM UTC+5:30, Rustom Mody wrote: >> Heres a (pr) approx >> >> $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in >> os.walk(".") if len(d+f) != 1])' > > Without pprint: (pooor) > > python -c 'import os; print "\n".join([ r

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

2014-05-30 Thread Chris Angelico
On Fri, May 30, 2014 at 4:04 PM, Rustom Mody wrote: > I thought when one signs up for python one has to sign an affidavit > saying: > "I shall not write one-liners\n" * 100 Certainly not. I write all my list comps on one line! *ducking for cover* ChrisA -- https://mail.python.org/mailman/listi

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

2014-05-29 Thread Rustom Mody
On Friday, May 30, 2014 12:15:46 PM UTC+5:30, Rustom Mody wrote: > Heres a (pr) approx > > $ python -c 'import os, pprint; pprint.pprint ([ r for r, d, f in > os.walk(".") if len(d+f) != 1])' Without pprint: (pooor) python -c 'import os; print "\n".join([ r for r, d, f in os.walk(".") if l

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

2014-05-29 Thread Rustom Mody
On Friday, May 30, 2014 11:34:36 AM UTC+5:30, Rustom Mody wrote: > On Friday, May 30, 2014 6:22:24 AM UTC+5:30, Chris Angelico 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

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

2014-05-29 Thread Rustom Mody
On Friday, May 30, 2014 6:22:24 AM UTC+5:30, Chris Angelico 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, fil

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

2014-05-29 Thread Chris Angelico
On Fri, May 30, 2014 at 12:34 PM, Zachary Ware 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 compet

Multi-line commands with 'python -c'

2014-05-29 Thread Zachary Ware
On Thursday, May 29, 2014, Chris Angelico > 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

Multi-line commands with 'python -c'

2014-05-29 Thread Chris Angelico
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) Solution 1: Syn