Check whether string is in CSV

后端 未结 4 1344
死守一世寂寞
死守一世寂寞 2021-02-01 19:23

I want to search a CSV file and print either True or False, depending on whether or not I found the string. However, I\'m running into the problem wher

4条回答
  •  走了就别回头了
    2021-02-01 20:11

    #!/usr/bin/python
    import csv
    
    with open('my.csv', 'r') as f:
        lines = f.readlines()
        cnt = 0
    
        for entry in lines:
            if 'foo' in entry:
                cnt += 1
    
        print"No of foo entry Count :".ljust(20, '.'), cnt
    

提交回复
热议问题