MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / import_attr_from_module

Function import_attr_from_module

_pydevd_bundle/pydevd_utils.py:494–517  ·  view source on GitHub ↗
(import_with_attr_access)

Source from the content-addressed store, hash-verified

492
493
494def import_attr_from_module(import_with_attr_access):
495 if "." not in import_with_attr_access:
496 # We need at least one '.' (we don't support just the module import, we need the attribute access too).
497 raise ImportError("Unable to import module with attr access: %s" % (import_with_attr_access,))
498
499 module_name, attr_name = import_with_attr_access.rsplit(".", 1)
500
501 while True:
502 try:
503 mod = import_module(module_name)
504 except ImportError:
505 if "." not in module_name:
506 raise ImportError("Unable to import module with attr access: %s" % (import_with_attr_access,))
507
508 module_name, new_attr_part = module_name.rsplit(".", 1)
509 attr_name = new_attr_part + "." + attr_name
510 else:
511 # Ok, we got the base module, now, get the attribute we need.
512 try:
513 for attr in attr_name.split("."):
514 mod = getattr(mod, attr)
515 return mod
516 except:
517 raise ImportError("Unable to import module with attr access: %s" % (import_with_attr_access,))

Callers 2

Calls

no outgoing calls

Tested by 1