3 examples of 'python from import *' in Python

Every line of 'python from import *' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
23def import_modules(source_code: str):
24 results = {}
25 imports = parse_imports(source_code)
26 for import_ in imports:
27 module = import_.module if import_.module else import_.name
28 loaded_module = importlib.import_module(module)
29
30 if not import_.name == module:
31 loaded_module = getattr(loaded_module, import_.name)
32
33 if import_.alias:
34 results[import_.alias] = loaded_module
35 else:
36 results[import_.name] = loaded_module
37
38 return results
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

365def visit_import(self, node):
366 """return an astroid.Import node as string"""
367 return "import %s" % _import_string(node.names)
22def visit_Import(self, node):
23 """
24 This executes every time an "import foo" style import statement
25 is parsed.
26 """
27 for n in node.names:
28 self.imports.append((n.name, n.asname, None))

Related snippets