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"
Morgan Thrapp
10k3 gold badges51 silver badges68 bronze badges
asked Jul 14, 2016 at 13:59
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>)
answered Jul 14, 2016 at 14:02
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.