How do you conver output of "popen('ls')" to a list?

Trent Mick trentm at ActiveState.com
Wed Feb 20 17:08:06 EST 2002


$ ls
bye.txt  hello.txt
$ python
>>> import os
>>> o = os.popen('ls')
>>> lines = o.readlines()
>>> o.close()
>>> lines
['bye.txt\012', 'hello.txt\012']
>>> files = [line.strip() for line in lines]   # strip off EOL characters
>>> files
['bye.txt', 'hello.txt']
>>>


Cheers,
Trent

-- 
Trent Mick
TrentM at ActiveState.com




More information about the Python-list mailing list