I want to know if multiple modules are imported, and have tried the following 3 ways. But I found their result are different. I wonder why directly using dir() in all(...) leads to incorrect result?
import re, os
# Approach 1
all(k in dir() for k in ('re', 'os')) # False
# Approach 2
're' in dir() and 'os' in dir() # True
# Approach 3
list = dir()
all(k in list for k in ['re', 'os']) # True