Я пытаюсь распаковать dict из списка и передать его методу класса __init__. Но где-то есть ошибка TypeError, которую я не могу разрешить. Я передаю только один dict длиной 13 (проверьте выходы типа () и 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