Py学习  »  Python

Python:named tuple.\u source在Python 3.7中不工作

Pietro Marsella • 5 年前 • 1394 次点击  

我试过这个密码

from collections import namedtuple
t = namedtuple('t', 'a b c')
i = t(1,2,3)
print(i._source, t._source)

但是当我运行它时它说没有属性 _source (用于 t 因此 i ). 从3.6开始就被淘汰了吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51950
 
1394 次点击  
文章 [ 1 ]  |  最新文章 5 年前
martineau
Reply   •   1 楼
martineau    5 年前

是的,如前所述 here ,属性 _source 已从中删除 namedtuples 在Python3.7中。

在版本3.7中更改: 移除 冗长的 参数和 _来源 属性。