When learning the book machine learning practice, I ran according to the code in the book and made an error, but there was no error prompt in the code. The error codes are as follows:
if type(secondDict[key])._name_ == 'dict':
Errors are reported as follows:
AttributeError: type object 'str' has no attribute '_name_'
Attribute error: the type object “STR” has no attribute “name”,
The error is caused by different versions. The author uses version 2. X, while I use version 3.7. X.
The type object “STR” in Python 3 does not have the “_name_” attribute, so we need to remove the attribute. In addition, this judgment statement was originally used to judge whether the node type is dict (Dictionary), but because the single quotation mark (”) is added, it becomes a string, which will cause other errors, so we also need to remove the single quotation mark.
Modify the error code as follows:
if type(secondDict[key]) == dict:
Just run it now.
- [Solved] Python Error: TypeError: ‘dict_keys’ object does not support indexing
- Error reporting of Python STR type dictionary conversion
- Python: `if not x:` VS `if x is not None:` VS `if not x is None:`
- [Solved] Vue3+ts+eslint Error: warning Unexpected any. Specify a different type, warning Delete `·` , Missing return type on function, Require statement not part of import statement
- Git commit -m ‘Add Readme’ error: pathspec ‘Readme” did not match any file(s) known to git
- Shell script execution error [: 0: unary operator expected
- JAVA Error: too many characters in character literal
- Several cases of error reporting in java.lang.nullpointerexception
- Flask Accessing an interface that returns a dictionary error: The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
- [How to Solve] ‘dict’ object has no attribute ‘has_key’