I have a list with string values that are changing asynchronously. I would like to continually check over the list until no item in the list contains a certain substring and then execute a command.
To make things less abstract I will explain my specific situation. I am using selenium to automate downloading several files, and after all the files have finished downloading I would like to close the webdriver. My current solution to the problem is the following:
while True:
for file in os.listdir(download_dir):
if 'tmp' in file.lower():
break
else:
driver.quit()
break
Basically, check if any element in the list (filenames in the download directory in this case) contains 'tmp' and if it does start checking again. If the whole list has been checked and there are no elements with 'tmp' in them quit the web driver and exit the loop.
This solution works fine, however in one of the stack overflow threads I used to come up with it (see here) many people said that, while something like this would work, it's probably a poor way to be doing it.
So my question is, is there a more pythonic way of doing this? Or if not just a better way in general? I don't have a problems with my solution, but some of the comments in the other answer give me a slight feeling that I should.