我知道namedtuple
类从2.6开始就存在。
有没有办法在Python 2.5中实现类似的功能,所以可以实现正常的元组?
Student = namedtuple('Student', 'name serial')
答案 0 :(得分:5)
implement named tuples in Python 2.4以后有一个配方。您可以将其与Python 2.7 here中的命名元组的实际实现进行比较。
答案 1 :(得分:3)
Python中namedtuple
的实际来源是此配方:Named Tuples。
得到的配方很受欢迎,因此建议并接受它包含在Py2.6的收集模块中。