# Importer Source: https://www.tensorplay.cn/docs/generated/tensorplay.package.Importer.html ```python class tensorplay.package.Importer ``` Represents an environment to import modules from. By default, you can figure out what module an object belongs by checking __module__ and importing the result using __import__ or importlib.import_module. tensorplay.package introduces module importers other than the default one. Each PackageImporter introduces a new namespace. Potentially a single name (e.g. ‘foo.bar’) is present in multiple namespaces. It supports two main operations: import_module: module_name -> module object get_name: object -> (parent module name, name of obj within module) The guarantee is that following round-trip will succeed or throw an ObjNotFoundError/ObjMisMatchError. module_name, obj_name = env.get_name(obj) module = env.import_module(module_name) obj2 = getattr(module, obj_name) assert obj1 is obj2 ```python get_name(obj: Any, name: str | None = None) → tuple[str, str] ``` Given an object, return a name that can be used to retrieve the object from this environment. Parameters: - obj – An object to get the module-environment-relative name for. - name – If set, use this name instead of looking up __name__ or __qualname__ on obj. This is only here to match how Pickler handles __reduce__ functions that return a string, don’t use otherwise. Returns: A tuple (parent_module_name, attr_name) that can be used to retrieve obj from this environment. To use it: ``` mod = importer.import_module(parent_module_name) obj = getattr(mod, attr_name) ``` Raises: - [ObjNotFoundError](/docs/generated/tensorplay.package.ObjNotFoundError.html#tensorplay.package.ObjNotFoundError) – we couldn’t retrieve obj by name. - ObjMisMatchError – we found a different object with the same name as obj. ```python abstractmethod import_module(module_name: str) → ModuleType ``` Import module_name from this environment. The contract is the same as for importlib.import_module. ```python whichmodule(obj: Any, name: str) → str ``` Find the module name an object belongs to. This should be considered internal for end-users, but developers of an importer can override it to customize the behavior. Based on the classic pickle.py approach, but modified to exclude the search into sys.modules.