为什么没有定义“ namedtuple()”? [关闭]

I'm trying to follow the example of using namedtuple( ) in the documentation, but the Traceback says the name namedtuple is not defined. Why does it happen? Did I do it wrong?

Traceback

评论
婚礼礼堂
婚礼礼堂

You need import collections up top, then you can do collections.namedtuple

You can also do from collections import namedtuple and it should work like in the docs

点赞
评论