newbie: strange python problem

maxx nospam at somedomain.com
Thu Apr 10 08:27:06 EDT 2003


Simple code (I think):

---
#!/usr/bin/python

import os

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?

maxx




More information about the Python-list mailing list