Good day! Learning to write in python. Please help. The fact is that there is one csv file there are stored texts and there are words more precisely 5 words you need to check for the presence of one of these 5 words in the texts of this file.
For example: in csv such texts: Good afternoon! My name is John! Hello! My name is Emma! My name is Emily!
Words: Good afternoon, Hello, Good evening.
my code is:
#! /usr/bin/env python # -*- coding: utf-8 -*- import csv import unicodecsv as csv import sys reload(sys) sys.setdefaultencoding('utf-8') result_read = ['Добрый день' ,'Здравствуйте','Доброе утро','Уважаемый','Уважаемая'] if __name__ == '__main__': print 'Starting...' with open('data.csv', 'r') as f: data = f.read().splitlines() # i = raw_input('Enter response: ') # data = [i] result = [] for lines in data: #sentences = filter(lambda x: len(x) > 0, entry.split('.')) if result_read in lines: #and len(sentences) > 5 and all([len(x.split()) > 4 for x in sentences]): result.append((lines, 'соответствует')) else: result.append((lines, 'не соответствует')) with open('result.csv', 'w') as f: for r in result: f.write(u'{}, {}\n'.format(r[0], r[1])) print 'Finished!'
grep -Ff phrases input.csvcommand? What does it mean that this is a csv file, and not any other text file? - jfs