Created
May 6, 2025 07:27
-
-
Save ynkdir/8c243ce2c2a8ccedbc12127897187678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import importlib | |
import inspect | |
class LazyImport: | |
def __init__(self, module): | |
self._module = module | |
def __getattr__(self, name): | |
try: | |
value = getattr(self._module, name) | |
if inspect.ismodule(value): | |
return LazyImport(value) | |
return value | |
except AttributeError: | |
pass | |
try: | |
return LazyImport(importlib.import_module(self._module.__name__ + "." + name)) | |
except ImportError: | |
raise AttributeError(f"module '{self._module.__name__}' has no attribute '{name}'") from None | |
# in win32more/__init__.py | |
# lazy = LazyImport(sys.modules[__name__]) | |
# then | |
# from win32more import lazy as win32more | |
# win32more.Windows.Win32.UI.WindowsAndMessaging.MessageBox(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment