def iter_imported_modules(node):
"""
Yield the imported module names from *node* where *node* is either an
ast.Import or ast.ImportFrom instance.
"""
if isinstance(node, ast.Import):
for alias in node.names:
yield alias.name
elif isinstance(node, ast.ImportFrom):
for alias in node.names:
yield node.module + '.' + alias.name
else:
raise ValueError('node must be an instance of either ast.Import or ast.ImportFrom')
评论列表
文章目录