Each line an element in an array when reading text file in Python
本问题已经有最佳答案,请猛点这里访问。
阅读文本文件时,我使用:
1 2 3 4 5 | import io with io.open('MasterList.txt', encoding='latin-1') as myfile: data=myfile.read().replace(' ', '') |
但是打印像
1 2 3 4 5 6 | import io data = [] with io.open('MasterList.txt', encoding='latin-1') as myfile: for i in myfile.readlines(): data.append(i) |
然后您可以循环
1 2 | if password in data: print"Password found in data" |