【发布时间】:2009-11-19 04:48:36
【问题描述】:
如何在不同的模块中返回函数的参数
#Module: functionss.py
def simple(a, b, c):
print "does something"
#Module: extract.py
#load the called module and function
def get_args(module_name, function_name):
modFile, modPath, modDesc = imp.find_module(module_name)
mod = imp.load_module(module_name,modFile,modPath,modDesc)
attr = getattr(mod, function_name)
#this is the part I don't get - how do I read the arguments
return = attr.get_the_args()
if __name__ == "__main__":
print get_args("functions.py", "simple")
#this would ideally print [a, b, c]
【问题讨论】:
-
看源码有什么问题?它是 Python——你有源代码,只需阅读它。是什么阻止了这种情况?
-
另外,
help()函数有什么问题?这通常会告诉你一切。这有什么问题?