I agree with the “don’t do this generally” consensus, but…
The correct answer is:
from importlib import reload
import X
reload(X)
from X import Y # or * for that matter
More Related Contents:
- How do I import a module given the full path?
- How to do relative imports in Python?
- How can I import other Python files?
- Importing modules: __main__ vs import as module
- How do I import other Python files?
- How does python find a module file if the import statement only contains the filename?
- Python import modules from a higher level package
- Prevent Python from caching the imported modules
- How can I import a module dynamically given the full path?
- ImportError: libSM.so.6: cannot open shared object file: No such file or directory
- How to properly use relative or absolute imports in Python modules?
- Importing a library from (or near) a script with the same name raises “AttributeError: module has no attribute” or an ImportError or NameError
- How can I do relative imports in Python?
- Recursive version of ‘reload’
- How to fix “Attempted relative import in non-package” even with __init__.py
- Installing python module within code
- ImportError: Cannot import name X
- Import a file from a subdirectory?
- Reading file using relative path in python project
- Relative imports – ModuleNotFoundError: No module named x
- Does python optimize modules when they are imported multiple times?
- How to import a Python class that is in a directory above?
- PYTHONPATH vs. sys.path
- How to dynamically load a Python class
- Importing installed package from script with the same name raises “AttributeError: module has no attribute” or “ImportError: cannot import name”
- Importing packages in Python
- Absolute imports in python not working, relative imports work
- Local import statements in Python
- Installing lxml module in python
- Importing module from string variable using “__import__” gives different results than a normal import statement