How to get the os.system data into a variable

Jarkko Torppa torppa at polykoira.megabaud.fi
Tue Dec 19 21:19:38 EST 2000


In article <91o5ih$2kv$1 at news.wrc.xerox.com>, jicman wrote:
>I know that
>
>t = os.system('ls -l')
>
>return code and assigns it to t.  I would like to get the data, not the code, 
>that is resulted from the command into a variable.  (i.e.

if 'ls -l' really is the command that you want to get the data from
then this does pretty much the same thing.
# 1.5 way
l=map(lambda x:(x,os.stat(x)),os.listdir('.'))
# 2.0 way
l=[ (e,os.stat(e)) for e in os.listdir('.') ]

the list is totally unformatted and as such more
suited for further processing. Look at stat module
for hints of what to do with the values.

-- 
 Jarkko Torppa                torppa at staff.megabaud.fi
  Megabaud Internet-palvelut



More information about the Python-list mailing list