6 examples of 'import dict python' in Python

Every line of 'import dict python' 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
214def _import_modules(import_list):
215 for module_name in import_list:
216 __import__(module_name)
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

90def __import__(name, globals=None, locals=None, fromlist=None):
91 """An alternative to the import function so that we can import
92 modules defined as strings.
93
94 This code was taken from: http://docs.python.org/lib/examples-imp.html
95 """
96 # Fast path: see if the module has already been imported.
97 try:
98 return sys.modules[name]
99 except KeyError:
100 pass
101
102 # If any of the following calls raises an exception,
103 # there's a problem we can't handle -- let the caller handle it.
104 module_name = name.split('.')[-1]
105 module_path = os.path.join(EXAMPLE_DIR, *name.split('.')[:-1])
106
107 fp, pathname, description = imp.find_module(module_name, [module_path])
108
109 try:
110 return imp.load_module(module_name, fp, pathname, description)
111 finally:
112 # Since we may exit via an exception, close fp explicitly.
113 if fp:
114 fp.close()
123def _import_module(d, mod_name, logger=None):
124 try:
125 if _is_python_package(d):
126 _mod_name = "{0}.{1}".format(basename(d), mod_name)
127 imported_module = _import_from_python_package(_mod_name, mod_name)
128 else:
129 imported_module = _import_directly(mod_name)
130
131 sys.modules[normalize_path(d) + "." + mod_name] = imported_module
132 except:
133 if logger:
134 logger.debug("Error loading plugin: {0}".format(mod_name), exc_info=sys.exc_info())
680def _import_module(module):
681 __import__(module)
682 return sys.modules[module]
69def import_module(module_name):
70 '''
71 Imports the specified module by name.
72 '''
73
74 parts = module_name.split('.')
75 module = __import__(module_name)
76 for part in parts[1:]:
77 module = getattr(module, part)
78 return module
266def _import_functs(mod, dct, names=None):
267 """
268 Maps attributes attrs from the given module into the given dict.
269
270 Args
271 ----
272 dct : dict
273 Dictionary that will contain the mapping
274
275 names : iter of str, optional
276 If supplied, only map attrs that match the given names
277 """
278 if names is None:
279 names = dir(mod)
280 for name in names:
281 if isinstance(name, tuple):
282 name, alias = name
283 else:
284 alias = name
285 if not name[0] == '_':
286 dct[name] = getattr(mod, name)
287 dct[alias] = dct[name]

Related snippets