namedtuple:预期1个参数,得到3

时间:2015-05-17 15:36:07

标签: python namedtuple

我有这个基本的命名元组:

from collections import namedtuple

DBInfos = namedtuple('dbname', 'dbpath', 'dbfile')

当我尝试用

实例化一个时
d = DBInfos._make(['test', 'a/b/c', '.index.db'])

我收到以下错误:

Traceback (most recent call last):
 File "./test.py", line 5, in <module>
 d = DBInfos._make(['test', 'a/b/c', '.index.db'])
 File "<string>", line 21, in _make
TypeError: Expected 1 arguments, got 3

但我不知道为什么:/

1 个答案:

答案 0 :(得分:3)

您对namedtuple功能的调用不正确。它应该是:

DBInfos = namedtuple('DBInfos', ['dbname', 'dbpath', 'dbfile'])

请参阅:https://docs.python.org/2.7/library/collections.html#collections.namedtuple