Python 2.5中的namedtuple

时间:2012-07-11 08:12:36

标签: python python-2.5

我知道namedtuple类从2.6开始就存在。 有没有办法在Python 2.5中实现类似的功能,所以可以实现正常的元组?

Student = namedtuple('Student', 'name serial')

2 个答案:

答案 0 :(得分:5)

implement named tuples in Python 2.4以后有一个配方。您可以将其与Python 2.7 here中的命名元组的实际实现进行比较。

答案 1 :(得分:3)

Python中namedtuple的实际来源是此配方:Named Tuples

  

得到的配方很受欢迎,因此建议并接受它包含在Py2.6的收集模块中。