MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / locate

Function locate

tools/python-3.11.9-amd64/Lib/pydoc.py:1797–1814  ·  view source on GitHub ↗

Locate an object by name or dotted path, importing as necessary.

(path, forceload=0)

Source from the content-addressed store, hash-verified

1795 return type(thing).__name__
1796
1797def locate(path, forceload=0):
1798 """Locate an object by name or dotted path, importing as necessary."""
1799 parts = [part for part in path.split('.') if part]
1800 module, n = None, 0
1801 while n < len(parts):
1802 nextmodule = safeimport('.'.join(parts[:n+1]), forceload)
1803 if nextmodule: module, n = nextmodule, n + 1
1804 else: break
1805 if module:
1806 object = module
1807 else:
1808 object = builtins
1809 for part in parts[n:]:
1810 try:
1811 object = getattr(object, part)
1812 except AttributeError:
1813 return None
1814 return object
1815
1816# --------------------------------------- interactive interpreter interface
1817

Callers 2

resolveFunction · 0.70
html_getobjFunction · 0.70

Calls 3

safeimportFunction · 0.85
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected