Skip to content

Instantly share code, notes, and snippets.

@fengxuway
Last active August 10, 2016 07:39
Show Gist options
  • Save fengxuway/7dbef9b7176995e2b2fe43740be7f750 to your computer and use it in GitHub Desktop.
Save fengxuway/7dbef9b7176995e2b2fe43740be7f750 to your computer and use it in GitHub Desktop.
根据函数名称或类名执行函数或得到实例对象
# 根据全局的对象名称获取对象实例,类似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