Single word search from CSV with multiple words in one cell

This question already has an answer here:

  • Does Python have a string 'contains' substring method? 13 answers

  • 除了解析csv文件之外,还可以查看所有列,并检查是否有一个字段包含关键字(您应该search in field使用search in field而不是==因为upsabraham指出),您还可以在此处保存一些处理能力,并检查关键字在该行的某处并按原样写入该行。

    # -*- coding: utf-8 -*-
    
    in_file = 'TestDomstol.csv'
    out_file = 'verdictsOutput.csv'
    search = raw_input("Enter keyword: ")
    
    with open(in_file, 'r') as verdictFileInput:
        header = verdictFileInput.next()
        with open(out_file, 'wb') as verdictFileOutput:
            verdictFileOutput.write(header)
            for line in verdictFileInput:
                if search in line:
                    verdictFileOutput.write(line)
    
    链接地址: http://www.djcxy.com/p/9394.html

    上一篇: 正则表达式或其他方式来检查变量中的单词?

    下一篇: CSV中的单词搜索,在一个单元格中有多个单词