bof*_*jas 0 python attributes initialization class function
说我有一个功能:
def test(ab):
print ab.a
print ab.b
Run Code Online (Sandbox Code Playgroud)
如何在不定义类的情况下轻松地将参数传递给此函数?我正在寻找以下内容:
test({4,5})
Run Code Online (Sandbox Code Playgroud)
要么
test(ab.a = 5, ab.b = 6)
Run Code Online (Sandbox Code Playgroud)
这是可能吗?更改功能'test'不是一个选项.
小智 6
import collections
ab = collections.namedtuple("AB", "a b")(a=4, b=5)
test(ab)
Run Code Online (Sandbox Code Playgroud)