我正在尝试在两个文件中匹配(什么是网络登录用户名)。All 是我(或将要)有兴趣匹配的名称的文本文件。目前,我正在做这样的事情:
def find_files(directory, pattern):
#directory= (raw_input("Enter a directory to search for Userlists: ")
directory=("c:\\TEST")
os.chdir(directory)
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
for filename in find_files('a-zA-Z0-9', '*.txt'):
with open (filename, "r") as file1:
with open ("c:/All.txt", "r") as file2:
list1 = file1.readlines()[18:]
list2 = file2.readlines()
for i in list1:
for j in list2:
if i == j:
我是 python 新手,想知道这是否是最好、最有效的方法。对我来说,即使是新手,似乎也有点笨拙,但以我目前的编码知识是我目前能想到的最好的。任何帮助和建议将不胜感激。