os.system output

Jonathan Soons jsoons at juilliard.edu
Wed Mar 21 17:32:39 CET 2001


I am trying to save the output of

>>>dirs = os.system('ls')

into a variable but I do not need any output to
the screen (altho it doesn't hurt). How do I
go about this?
My fat book only explains how to get output to the screen.

I could do

>>>os.system('ls > file')
>>>f = open('file')
>>>dirs = f.readlines()

but it looks crude. Is there a better way?




More information about the Python-list mailing list