My Generator Code
def search(query):
dir_path = os.path.realpath("C:/")
for root, dirs, files in os.walk(dir_path):
for file in files:
if query.lower() in str(file).lower():
yield (root, file)
for directory in dirs:
if query.lower() in str(directory).lower():
yield (root, directory)
I want to be able to fetch the results, showing them and run my application simultaneously.
When I do this it hangs the program till the loop is over then show the results
def pushButtonFunc():
text = self.LocalSearchBar.text()
newWindow = QtWidgets.QDialog(ProjectOSP)
newWindow.resize(1201, 861)
listWidget = QtWidgets.QListWidget(newWindow)
for root, file in search(text):
ite = QtWidgets.QListWidgetItem(file)
listWidget.addItem(ite)```
可能的修复方法:
最后两个选项中哪一个是最好的,这在很大程度上取决于你的应用程序、你的特定用例,以及更多的代码,而不是方便地链接到这里。这真的是一个只有你才能打的电话
相关问题 更多 >
编程相关推荐