Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提取python方法参数的数量和名称_Python_Function_Arguments - Fatal编程技术网

提取python方法参数的数量和名称

提取python方法参数的数量和名称,python,function,arguments,Python,Function,Arguments,如何返回不同模块中函数的参数 #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)

如何返回不同模块中函数的参数

#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]
用于“重载”(自省功能)

使用
\uuuu import\uuuuu
导入模块(给定其模块名称-
“functions.py”
是指定模块名称的糟糕方法;-)


使用
getattr(moduleobject,functionname)
获取给定模块对象和函数名称的函数对象。

读取源代码有什么问题?这是Python——你有了源代码,只要读一下就可以了。是什么阻止了这一点?此外,
help()
函数有什么问题?这通常会告诉你一切。这有什么不对?看到了吗