我有这个基本的命名元组:
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
但我不知道为什么:/
答案 0 :(得分:3)
您对namedtuple
功能的调用不正确。它应该是:
DBInfos = namedtuple('DBInfos', ['dbname', 'dbpath', 'dbfile'])
请参阅:https://docs.python.org/2.7/library/collections.html#collections.namedtuple