class LazyImport: def __init__(self,module_name): self.module_name = module_name self.module = None def __getattr__(self,name): if self.module is None: self.module = __import__(self.module_name) return getattr(self.module,name) string = LazyImport("string") print string.lowercase
时间: 2024-10-21 18:18:58