Nested loop not working

Johann Spies johann.spies at gmail.com
Fri Jul 16 10:34:19 EDT 2010


I am overlooking something stupid.

I have two files: one with keywords and another with data (one record per line).

I want to determine for each keyword which lines in the second file
contains that keyword.

The following code is not working.  It loops through the second file
but only uses the first keyword in the first file.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re

keywords = open("sleutelwoorde",'r')
data = open("sarua_marine_sleutelwoorde.csv",'r')

remove_quotes = re.compile('"')


for sw in keywords:
    for r in data:
        swc = remove_quotes('',sw)[:-1]
        if swc in r.lower():
                print swc + ' ---> ' + r
                print swc

What am I missing?

Regards
Johann

-- 
"Finally, brethren, whatsoever things are true,  whatsoever things are
honest, whatsoever things are  just, whatsoever things are pure,
whatsoever things are lovely, whatsoever things are of good report; if
there be any virtue, and if there be any praise, think on these
things."    Philippians 4:8



More information about the Python-list mailing list