output of shell command
Sheila King
sheila at spamcop.net
Mon Feb 26 17:20:06 EST 2001
On Mon, 26 Feb 2001 22:11:30 GMT, grante at visi.com (Grant Edwards) wrote in
comp.lang.python in article <mwAm6.188$V6.36687 at ruti.visi.com>:
:In article <n9hl9tc8v4d3bg7vkoq29k4v6oppq6lon3 at 4ax.com>, Sheila King wrote:
:>You can return a single string by turning the readlines() into read()
:>like this:
:>
:>os.popen().read()
:>
:>Or, do this (silly):
:>
:>"\n".join(os.popen("dir").readlines()))
:
:[I swear, no matter how many times I see that syntax, it looks
:goofy.]
I am not personally fond of it, myself. I wonder, that join should be a method
of the LIST OF STRINGS, rather than of the string concatenator.
I'm just trying to get more used to the 2.0 way of doing things.
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/
:Likewise, if you want a list of strings from commands.getoutput()
:you can use the split() method:
:
:commands.getoutput().split('\n')
More information about the Python-list
mailing list