Bryan Fodness wrote: > I try this, > > f = open('TEST1.MLC') > > fields = {} > > for line in f: > if line.split()[0] == 'Field': > field = int(line.split()[-1]) > elif line.split()[0] == 'Leaf': > fields[field] = line.split()[-1] > else: > line = f.next() > > and get, > > Traceback (most recent call last): > File "<pyshell#1>", line 1, in <module> > line.split()[0] > IndexError: list index out of range
For blank lines, line.split() is [] so there is no line.split()[0]. Try skipping blank lines before you split. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor