Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
说我有一个功能:
def test(ab): print ab.a print ab.b
如何在不定义类的情况下轻松地将参数传递给该函数?我正在寻找类似的东西:
test({4,5})
或者
test(ab.a = 5, ab.b = 6)
这是可能吗?更改功能“测试”不是一种选择。
使用collections.namedtuple:
collections.namedtuple
import collections ab = collections.namedtuple("AB", "a b")(a=4, b=5) test(ab)