尝试将从列表中解压缩的字典传递给__init__方法时,TyperError

时间:2019-03-30 23:56:56

标签: python-3.x init

我正在尝试从列表中解译字典并将其传递给类的__init__方法。但是在某个地方有TypeError,我无法解决。我只传递了一个长度为13的字典(检查type()和len()输出)。

Python 3.7.2,Windows 10。

packed:
[{
    'external_ids': {},
    'play_offset_ms': 9340,
    'genres': [{'name': 'Alternative'}],
    'external_metadata': {},
    'label': 'Vagrant Records',
    'release_date': '2018-10-11',
    'artists': [{'name': 'LP'}],
    'title': 'Recovery',
    'duration_ms': 234620,
    'album': {'name': 'Recovery'},
    'acrid': '12655602970c4b9fecd46fd946f2b3d8',
    'result_from': 3,
    'score': 100
}]
        ...
        if not status:
            packed = meta['metadata']['music']
            self.meta = Meta(*packed)
            print(*packed, type(*packed), len(*packed))
        else:
            print(error_codes[status])

class Meta:
    def __init__(self, meta):
        pass
Output:
{'external_ids': {}, 'play_offset_ms': 9340, 'genres': [{'name': 'Alternative'}], 'external_metadata': {}, 'label': 'Vagrant Records', 'release_date': '2018-10-11', 'artists': [{'name': 'LP'}], 'title': 'Recovery', 'duration_ms': 234620, 'album': {'name': 'Recovery'}, 'acrid': '12655602970c4b9fecd46fd946f2b3d8', 'result_from': 3, 'score': 100} <class 'dict'> 13
Traceback (most recent call last):
  File "C:/Users/Ledor/Documents/PycharmProjects/Tbot/objects.py", line 215, in <module>
    a1.recognize()
  File "C:/Users/Ledor/Documents/PycharmProjects/Tbot/objects.py", line 109, in recognize
    self.meta = Meta(*packed)
TypeError: __init__() takes 2 positional arguments but 6 were given

0 个答案:

没有答案