Last active
August 10, 2016 07:39
-
-
Save fengxuway/7dbef9b7176995e2b2fe43740be7f750 to your computer and use it in GitHub Desktop.
根据函数名称或类名执行函数或得到实例对象
This file contains 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
# 根据全局的对象名称获取对象实例,类似java的class.forName | |
self.obj = globals()[api](*args, **kwargs) | |
# 根据方法名称执行方法 | |
attr = getattr(self, api) | |
attr(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment