On Fri, Jul 16, 2010 at 8:34 AM, Johann Spies <johann.sp...@gmail.com> wrote: > 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?
Not sure about the loop, but this line looks incorrect: swc = remove_quotes('',sw)[:-1] I don't think a compiled regular expression object is callable; you have to call one of its methods. HTH, Ian -- http://mail.python.org/mailman/listinfo/python-list