Skip to content

Instantly share code, notes, and snippets.

@applenob
Created June 9, 2020 03:22
Show Gist options
  • Save applenob/0fb2e5e7b5b2fcc0bd3e40190a609543 to your computer and use it in GitHub Desktop.
Save applenob/0fb2e5e7b5b2fcc0bd3e40190a609543 to your computer and use it in GitHub Desktop.
import importlib
def find_name_path(root, name):
res = []
try:
m = importlib.import_module(root)
except (AttributeError, ModuleNotFoundError) as e:
return res
if name in dir(m):
res.append(f"{root}.{name}")
for cand_root in dir(m):
cand_root = f"{root}.{cand_root}"
sub_res = find_name_path(cand_root, name)
if len(sub_res): res += sub_res
return res
print(find_name_path("tensorflow.compat.v1", "dynamic_rnn"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment