Skip to content

Add API to locate package modules #6275

Closed
@Nic-Ma

Description

@Nic-Ma

Is your feature request related to a problem? Please describe.
Originally posted by @ericspod in #6181 (review):
I see you're using pydoc.locate and I wonder if we should have our own function in monai.utils.module for doing this. This is a topic for some other time and place but I had used something like this in the past that worked well enough:

def find_type_def(qualified_name: str):
    if "." not in qualified_name:
        modname, defname = "builtins", qualified_name
    else:
        modname, defname = qualified_name.rsplit(".", 1)

    mod = __import__(modname)
    return getattr(mod, defname)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions