Issue
Something went wrong with python3.10, no warning or any notice in the Pycharm validation. It just recommended the space by following the PEP 8: E231 missing white space after ':'
class Margin:
def __init__(self):
self.__margin = {}
def setMargin(self, value: dict= None) -> None:
self.__margin.update(value or {'all': '', 'android': {}, 'ios': {}})
Calling the method without a parameter
obj = Margin()
obj.setMargin()
Then everything was fine with adding space, but on the run time, it showed me the error.
File "/var/www/avb/n.py", line 1195, in setMargin
self.__margin.update(value or {'all': '', 'android': {}, 'ios': {}})
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Solution
You get this error generally,
when you try to update a dictionary like this:
d = {}
d.update([(100,)])
#or
d.update([[1]])
#output
ValueError: dictionary update sequence element #0 has length 1; 2 is required
You also get this error when you have dictionary inside a string like this:
d = '{"a":1,"b":2}'
then you try to convert it into a dictionary by:
dict(d)
#output
ValueError: dictionary update sequence element #0 has length 1; 2 is required
You have to check how you have defined your class and how the object obj
is created.
Answered By - Goku - stands with Palestine
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.