You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
passing a dict to bytes() gives unhelpful error message #79136
bytes() doesn't accept a dict as parameter. If you attempt to pass one, you receive a TypeError with the baffling message "'str' object cannot be interpreted as an integer".
>> bytes({'a':1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
Activity
marnanel commentedon Oct 10, 2018
bytes() doesn't accept a dict as parameter. If you attempt to pass one, you receive a TypeError with the baffling message "'str' object cannot be interpreted as an integer".
>> bytes({'a':1}) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object cannot be interpreted as an integerserhiy-storchaka commentedon Oct 10, 2018
bytes() accepts:
Dict is an iterable. But iterating it produces string object which cannot be interpreted as an integer.
ericvsmith commentedon Oct 10, 2018
You can in fact pass a dict to bytes(), as long as the keys are ints in the correct range:
I'm not claiming it's very useful, but it does conform to the docs. I'm not sure the error message can be improved, so I suggest closing this issue.
rhettinger commentedon Oct 11, 2018
I concur.