Your code is almost correct.
See __import__
function.
def doSomething(name):
name = "package." + name
mod = __import__(name, fromlist=[''])
mod.doSomething()
More Related Contents:
- How to do relative imports in Python?
- How to import a module given its name as string?
- Dynamically set local variable [duplicate]
- How to import the class within the same directory or sub directory?
- Automatically create requirements.txt
- How to check if a Python module exists without importing it
- Importing files from different folder
- Relative imports in Python 3
- Relative imports – ModuleNotFoundError: No module named x
- adding directory to sys.path /PYTHONPATH
- How to import a Python class that is in a directory above?
- Absolute vs. explicit relative import of Python module
- In Python, what happens when you import inside of a function? [duplicate]
- Is `import module` better coding style than `from module import function`?
- Why use sys.path.append(path) instead of sys.path.insert(1, path)?
- How to unimport a python module which is already imported?
- Why can’t Python import Image from PIL?
- Local import statements in Python
- Python: reload component Y imported with ‘from X import Y’?
- How does one do the equivalent of “import * from module” with Python’s __import__ function?
- When to use os.name, sys.platform, or platform.system?
- Python import modules from a higher level package
- How to fix “no module named ‘app_one'”
- How to solve import error for pandas?
- Installing lxml module in python
- Dynamically creating classes – Python
- Python import error: cannot import name ‘six’ from ‘sklearn.externals’
- Importing module from string variable using “__import__” gives different results than a normal import statement
- Recursive version of ‘reload’
- How to add a Python import path using a .pth file