Python search a file for text using input from another file

后端 未结 5 514
梦如初夏
梦如初夏 2021-01-20 11:24

I\'m new to python and programming. I need some help with a python script. There are two files each containing email addresses (more than 5000 lines). Input file contains em

5条回答
  •  野的像风
    2021-01-20 11:41

    I think your issue stems from the following:

    name = fd.readline()
    if name[1:-1] in names:
    

    name[1:-1] slices each email address so that you skip the first and last characters. While it might be good in general to skip the last character (a newline '\n'), when you load the name database in the "dfile"

    with open(inputfile, 'r') as f:
        names = f.readlines()
    

    you are including newlines. So, don't slice the names in the "ifile" at all, i.e.

    if name in names:
    

提交回复
热议问题