requestion regarding regular expression

Kent Johnson kent at kentsjohnson.com
Fri Apr 14 11:48:48 EDT 2006


BartlebyScrivener wrote:
> Kent,
> 
> Running
> 
> path = "d:/emacs files/emacsinit.txt"
> lines = open(path).readlines()
> # my defun lines are lowercase,
> # next two lines are all on one
> starts = [i for i, line in enumerate(lines) if
> line.startswith('(defun')]
> for i, start in starts:
>     while start > 0 and lines[start-1].startswith(';'):
>         starts[i] = start = start-1
>         print starts
> 
> I get
> 
> File "D:\Python\findlines.py", line 7, in __main__
>     for i, start in starts:
> TypeError: unpack non-sequence

Sorry, should be
   for i, start in enumerate(starts):

start is a specific start line, i is the index of that start line in the 
starts array (so the array can be modified in place).

Kent



More information about the Python-list mailing list