newbie: strange python problem
Peter Hansen
peter at engcorp.com
Thu Apr 10 08:57:04 EDT 2003
maxx wrote:
>
> Simple code (I think):
> for line in os.popen('ls -la /').readlines():
> direntry = line.split()
> print direntry
> print direntry[0]
> print direntry[1]
> print direntry[2]
> ---
>
> No list-items with an index above 1 are printed. They produce a
> 'IndexError: list index out of range' error... which is strange, because
> the list 'direntry' is 9 items large, so listitems up to index 8 should be
> printed... right?
Check the output of "ls -la /" manually... the first line does
*not* have more than two items in it... if you were to change
the first line above to this, it would work, though I suspect
there is another option to "ls" which would also suppress
that extra output.
> for line in os.popen('ls -la /').readlines()[1:]:
-Peter
More information about the Python-list
mailing list