Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Jeff Younker
On Nov 1, 2007, at 3:04 PM, Alan Gauld wrote: > Where does the if/else syntax come from? It doesn't > seem to work on my Python 2.4. Is it a new feature in 2.5? Yes, it's a new feature in 2.5. - Jeff Younker - [EMAIL PROTECTED] ___ Tutor maillist -

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Alan Gauld
"Eric Brunson" <[EMAIL PROTECTED]> wrote >last = Popen( command, > stdin=last.stdout if last else None, > stdout=PIPE ) Where does the if/else syntax come from? It doesn't seem to work on my Python 2.4. Is it a new feature in 2.5? Alan G. ___

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread jay
Eric and Eric :-) Thanks both for the suggestions! I learned from each! I believe the small function will work for me. Its simple since I don't have to track each pipe I open with a variable. I had no idea I could do that nifty if/then for the stdin, that makes it so easy. :-) Thanks again! J

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Alan Gauld
"jay" <[EMAIL PROTECTED]> wrote > I'm a little stumped as to how to handle the variables. If I have > an > arbitrary number of PIPES, how do I declare my variables (p1, p2, > p3, > etc...) ahead of time in the function?? How about passing a list of pipes? Then you can access them as pipes[0]

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Eric Brunson
jay wrote: > Hello, > > If I have multiple Popen calls I need to make, how can I turn these > into a function? Since you're only interested in the output of the last command on the pipeline, I don't see a reason to keep track of them all. I'd do something like this: def pipeline( *commandlist

Re: [Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread Eric Walstad
Hi Jay... jay wrote: ... > I would be sending an arbitrary number of PIPES with each function call. > > I'm a little stumped as to how to handle the variables. If I have an > arbitrary number of PIPES, how do I declare my variables (p1, p2, p3, > etc...) ahead of time in the function?? > > Tha

[Tutor] Turning multiple Popen calls into a function

2007-11-01 Thread jay
Hello, If I have multiple Popen calls I need to make, how can I turn these into a function? from subprocess import Popen, PIPE p1 = Popen(['ls', '-l', '-a', '/etc'],stdout=PIPE) p2 = Popen(['grep', 'hosts'], stdin=p1.stdout, stdout=PIPE) p3 = Popen(['awk', '{print $1}'], stdin=p2.stdout, stdout=