How do I use this format of code to find if a module exists within a python program? I know there are similar questions like this, but i need to specifically use exec() to parse an import statement.
def file_exists(name):
try:
exec()
return True #if the file does exist
except:
return False
#tests
file_exists(module1) #should return true because there is a module named module1
file_exists(module2) #should return false because there is not a module named module2.
source https://stackoverflow.com/questions/67766657/how-do-i-use-exec-to-parce-an-import-statement-to-find-if-a-module-exists-with
Comments
Post a Comment