MartinD wrote: > Hi, > > I'm new to Python. > Does someone has an idea what's wrong. I tried everything. The only regex > that is tested is the last one in a > whole list of regex in keywords.txt > Thanks! > Martin > > > ######## > def checkKeywords( str, lstKeywords ): > > for regex in lstKeywords: > match = re.search(regex, str,re.IGNORECASE) > # If-statement after search() tests if it succeeded > if match: > print match.group() ##just debugging > return match.group() ## 'found! > > return > > ######### > > keywords1 = [line for line in open('keywords1.txt')] > resultKeywords1 = checkKeywords("string_to_test",keywords1) > print resultKeywords1 >
Hi Martin, It is always helpful to provide python version, operating system version, full error message, and input/expected output for the code. Now I can tell you are using Python 2.x but without having any clue what is in keywords1.txt it is impossible to figure out what the problem might be. Other than using regular expressions that is. :) Ramit Prasad This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list