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

Jarkko Torppa torppa at polykoira.megabaud.fi
Tue Mar 12 12:25:32 EST 2002


In article <slrna8sdnl.e2.gminick at hannibal.localdomain>, Wojtek Walczak wrote:
>** Since micro$oft is stupid it doesn't mean
>** that you should be stupid too - do NOT toppost.
>Dnia Wed, 20 Feb 2002 10:54:13 +0100, husam napisa³(a):
>>thanks for reply.
>
>---------
>#!/usr/local/bin/python2.2
>
>import os
>
>blah = os.popen('ls').read()
>i,n,tabl,blen=0,0,[],len(blah)
>
>while i < blen:
>   tmp = i
>   i = blah.index('\n', i)
>   tabl.append(blah[tmp:i])
>   n+=1
>   i+=1
>
>for a in tabl:
>   print a
>---------

What's wrong with:
>> [ x[:-1] for x in os.popen('ls').readlines() ]
or better yet (no fork tax)
>> os.listdir('.')

-- 
Jarkko Torppa, Elisa Internet



More information about the Python-list mailing list