MCPcopy
hub / github.com/pandas-dev/pandas / get_callable

Function get_callable

web/pandas_web.py:361–384  ·  view source on GitHub ↗

Get a Python object from its string representation. For example, for ``sys.stdout.write`` would import the module ``sys`` and return the ``write`` function.

(obj_as_str: str)

Source from the content-addressed store, hash-verified

359
360
361def get_callable(obj_as_str: str) -> object:
362 """
363 Get a Python object from its string representation.
364
365 For example, for ``sys.stdout.write`` would import the module ``sys``
366 and return the ``write`` function.
367 """
368 components = obj_as_str.split(".")
369 attrs = []
370 while components:
371 try:
372 obj = importlib.import_module(".".join(components))
373 except ImportError:
374 attrs.insert(0, components.pop())
375 else:
376 break
377
378 if not obj:
379 raise ImportError(f'Could not import "{obj_as_str}"')
380
381 for attr in attrs:
382 obj = getattr(obj, attr)
383
384 return obj
385
386
387def get_context(config_fname: pathlib.Path, **kwargs):

Callers 1

get_contextFunction · 0.85

Calls 4

splitMethod · 0.80
joinMethod · 0.45
insertMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected