python的动态加载机制??

 

 

if __name__ == '__main__':
    
    import sys
    from PyQt5.QtWidgets import QApplication
    app = QApplication(sys.argv)  
    
    
#####################################################   
    
    print('main')
    import sys
    sys.path.append("../")
    
    module_name = "view"   #模块名  
    class_name = "HomeView" #类名     
    method = "show"          #方法名  
    module = __import__(module_name) # import module  
    print ("#module:",module  )
    print('dir', dir(module))
    cl = getattr(module,class_name)    
    print("#class:",cl  )
    

    
    obj = cl() # new class  
    print("#obj:",obj  ) 
    mtd = getattr(obj,method)  
    print("#method:",mtd  ) 
    mtd() # call def  
    
    
    
#####################################################   
    sys.exit(app.exec_())

 

需要在__init__.py文件中引出才行....囧

 

 

今天未来得及看的:

https://github.com/processone/grapherl

http://toutiao.com/i6215417552374333953/?tt_from=mobile_qq&utm_campaign=client_share&app=news_article&utm_source=mobile_qq&iid=3160476964&utm_medium=toutiao_ios

 

posted @ 2015-11-11 17:32  宁静的天空  阅读(769)  评论(0编辑  收藏  举报