0

I have a string which contains the name of a library that I want to import. How can I import that library dynamically?

For example:

library = "mylibrary"
0

1 Answer 1

1

you can use python default function __import__ to import modules.

mod = __import__(module)

but path of this module need to be appended in sys.path

sys.path.insert(0, <path of module>)
Sign up to request clarification or add additional context in comments.

1 Comment

Best practice is to use importlib.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.