[Tutor] Popen? or something else
Israel C. Evans
israel at uandmedance.com
Wed Dec 22 22:24:21 CET 2004
Fun!
testo = [line for line in commands.getoutput('ls -la').split('\n')]
for line in testo:
print line
spits out nicely formatted ls data.
It's Shelly!
Ertl, John wrote:
>Hugo,
>
>That looks like it will work great.
>
>Thanks,
>
>John
>
>-----Original Message-----
>From: Hugo González Monteverde [mailto:hugonz-lists at h-lab.net]
>Sent: Wednesday, December 22, 2004 12:41
>To: tutor at python.org
>Cc: Ertl, John
>Subject: Re: [Tutor] Popen? or something else
>
>You may use the 'commands' module, if your subprocess should return
>right away, then you can use:
>
>##
>import commands
>
>mystring = commands.getoutput("dtg")
>
>##
>
>then mystring should have "2004122212" (and possibly '\n', but you'll
>have to check that out, not sure about your command)in it...
>
>Hope it helps, it sure is quicker than popen (I only use popen if I need
>to keep reading the output, for a one-time capture, I personally prefer
>the "commands" module...)
>
>Hugo
>
>
>Ertl, John wrote:
>
>
>>Roger,
>>
>>I have been doing it the Pythonic way (that is why I have no idea about
>>
>>
>how
>
>
>>Popen works) but I need to make sure (the systems guys called me on it) I
>>use the same dtg as everyone else...it is possible (has not happened yet
>>
>>
>in
>
>
>>20 years) it could be set to something else.
>>
>>
>>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
>
More information about the Tutor
mailing list