在Python中读取文本文件时,每行都包含一个数组中的元素

这个问题在这里已经有了答案:

  • 在Python中,如何逐行读取文件到列表中? 35个答案

  • import io
    
    data = []
    with io.open('MasterList.txt', encoding='latin-1') as myfile:
        for i in myfile.readlines():
            data.append(i)
    

    然后,您可以循环data并将其与输入的password进行比较。 您可以使用:

    if password in data:
        print "Password found in data"
    
    链接地址: http://www.djcxy.com/p/42349.html

    上一篇: Each line an element in an array when reading text file in Python

    下一篇: Read username and password from a file