python-like style

Giorgi Lekishvili gleki at gol.ge
Wed Aug 21 11:01:07 EDT 2002


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.

Of course, I can do it ina n OO manner.

Anyway, I would like to do it in a functional manner.
Here comes, what I was trying to do.
>>>f=open(fn, 'r')
>>>i=iter(f)
>>>def getit(it, kw):
...     if string.find(it, kw)>0:
...         return it.next()
...     else:
...         return 0
>>>kw='<'
>>>rz=filter(None, map(apply(getit, s, kw), i))

No, the traceback:
File "D:\Python22\wxPython\tools\boa\ExternalLib\PythonInterpreter.py",
line 65, in push
    exec code in self.locals
  File "<console>", line 1, in ?
exceptions.NameError : name 's' is not defined

Thanks in advance.
Greetings,
Giorgi

PS. I am using Py 2.2.x, Boa.




More information about the Python-list mailing list