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
  • 9,748
  • 3
  • 46
  • 67
monster
  • 61
  • 7

1 Answers1

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>)
Pradip Das
  • 728
  • 1
  • 7
  • 16