getattr 后面有两个元组
getattr with two tuples after it
我正在使用一个代码库,其中包含一行我真的无法理解:
x, x, z = getattr(ReceiveFile, maxsizes)(input, args)
所以如果最后没有第二个元组,它就是
x, y, z = ReceiveFile.maxsizes
如何解释末尾的元组 (input, args)
?我不能那么容易 运行 这段代码并使用调试器来理解..
getattr
是 return 一个函数,然后用 input
和 args
作为参数调用它。然后该函数的 return 值被解压缩为 x
、y
和 z
.
加长版与
相同
f = getattr(ReceiveFile, maxsizes)
x, y, z = f(input, args)
给定 maxsizes
变量的字符串值:
maxsizes = "abc"
以下
x, x, z = getattr(ReceiveFile, maxsizes)(input, args)
相当于:
x, x, z = ReceiveFile.abc(input, args)
或者换句话说:对象 ReceiveFile
有一个名为 maxsizes
的方法(即 ReceiveFile.abc
),该方法使用参数 input
和 args
。括号不表示 tuple
,而是函数调用。
我正在使用一个代码库,其中包含一行我真的无法理解:
x, x, z = getattr(ReceiveFile, maxsizes)(input, args)
所以如果最后没有第二个元组,它就是
x, y, z = ReceiveFile.maxsizes
如何解释末尾的元组 (input, args)
?我不能那么容易 运行 这段代码并使用调试器来理解..
getattr
是 return 一个函数,然后用 input
和 args
作为参数调用它。然后该函数的 return 值被解压缩为 x
、y
和 z
.
加长版与
相同f = getattr(ReceiveFile, maxsizes)
x, y, z = f(input, args)
给定 maxsizes
变量的字符串值:
maxsizes = "abc"
以下
x, x, z = getattr(ReceiveFile, maxsizes)(input, args)
相当于:
x, x, z = ReceiveFile.abc(input, args)
或者换句话说:对象 ReceiveFile
有一个名为 maxsizes
的方法(即 ReceiveFile.abc
),该方法使用参数 input
和 args
。括号不表示 tuple
,而是函数调用。