延迟模块导入

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
原文地址:https://www.cnblogs.com/olivetree123/p/4857034.html