我想在txt文件中搜索列表元素



我想在txt文件中搜索列表元素。然而,这段代码我没有得到想要的结果。我试过几种方法,但没有一种真的有效。

def run(self):
hostname = self.queue.get()
with open('allhosts.txt', "r+") as file1:
fileline1 = file1.readlines()
for x in hostname:
for line in fileline1:
if x in line:
self.found.emit(hostname)
else:
self.notFound.emit(hostname)

在这种情况下使用regx

import re
str = open('a.txt', 'r').read()
m = re.search('(?<=hostname)(.*)', str)
print ("hostname",(m.groups()))

如果你没有得到输出。请删除文本文件截图

最新更新