码迷,mamicode.com
首页 > 其他好文 > 详细

延迟模块导入

时间:2015-10-06 14:08:23      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

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

 

延迟模块导入

标签:

原文地址:http://www.cnblogs.com/olivetree123/p/4857034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!