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?
- 积分
0 - 话题
0 - 评论
3151 - 注册排名
1979
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?
You need
import collections
up top, then you can docollections.namedtuple
You can also do
from collections import namedtuple
and it should work like in the docs