0
我想做类似于this post的东西,但是在python中。Python - 将参数从一个函数传递给嵌套函数
基本上...我想从功能1(ABC)的自变量传递到函数2为类型=(ABC)
伪代码如下:基于伪代码
function1 (*args, abc):
print xyz
function2(type=abc)
我想做类似于this post的东西,但是在python中。Python - 将参数从一个函数传递给嵌套函数
基本上...我想从功能1(ABC)的自变量传递到函数2为类型=(ABC)
伪代码如下:基于伪代码
function1 (*args, abc):
print xyz
function2(type=abc)
:
def function2(type):
print type
def function1(abc, *args):
print "something"
function2(type=abc)
>>> function1("blah", 1, 2, 3)
something
blah
但基于你的链接问题,也许你想通过可变参数:
def function2(type, *args):
print type, args
def function1(abc, *args):
print "something"
function2(abc, *args)
>>> function1("blah", 1, 2, 3)
something
blah (1, 2, 3)
有什么问题比争论在'功能1()'秩序的其他的伪代码? –
python是一种动态语言,所以你不需要传递一个对象的类型。只是使用func1(* args)很好。如果你想处理这个类型,通过代码检查func2里面:(type(args [1])== abc) – fanlix