python-like style
Mike C. Fletcher
mcfletch at rogers.com
Wed Aug 21 11:26:48 EDT 2002
Here's another approach:
>>> file = open( somefile ).readlines()
>>> keyword = '('
>>> [ file[i+1]
for i in range(len(file)-1)
if keyword in file[i]
]
The problem with your code is that, as the error notes, 's' is not
defined, you also seem to be using the iterator as both a string
representing the last result, and an object matching the iterator
protocol. As far as I know, that doesn't work, but then, I've not yet
used an iterator in my own code :) .
HTH,
Mike
Giorgi Lekishvili wrote:
> Hi all!
>
> Description of my task:
> Given a file. Given a list of keywords.
> Task:
> test whether a keyword is in the line and return the NEXT line. More
> precisely, the list of all such lines.
...
>>>>rz=filter(None, map(apply(getit, s, kw), i))
...
> exceptions.NameError : name 's' is not defined
...
More information about the Python-list
mailing list