[Tutor] Possible to search text file for multiple string values at once?

W W srilyk at gmail.com
Fri Jan 23 19:47:07 CET 2009


On Fri, Jan 23, 2009 at 12:38 PM, bob gailer <bgailer at gmail.com> wrote:

> Scott Stueben wrote:
>
>> Hi all,
>>
>> I understand that python excels at text processing, and wondered if
>> there is a way to use python to accomplish a certain task.  <snip>
>> I would love to set up a script to parse a file and show results from
>> a list of strings.  Is this possible with python?
>>
>>
>
> Yes - and also possible with almost all other programming languages.
> Here is one of several ways to do it in Python:
>
> for first_name in ('Bob', 'John', 'Joe', 'Jim', 'Fred'):
>  if  first_name in text:
>   print first_name, 'found'
>

Another option, if you really like sql, is to import sqlite3 and then parse
your text file into a sqlite database. That's probably overkill, of course.
But it's a possibility.
It really depends on what matters most. Speed? Comfort(with syntax)? Ease of
use? That will give you an idea of which tools you should use.

HTH,
Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090123/81239e5d/attachment.htm>


More information about the Tutor mailing list