AttributeError: ' dict ' object has no attribute ' item '
This error means that python cannot find the attributes of the corresponding object, and the beginners don’t know enough about the function object, which leads to errors
Original code:
favorite_languages = { ' jen ' : ' python ' , ' sarah ' : ' c ' , ' edward ' : ' ruby ' , ' phil ' : ' python ' , } for name,language in favorite_languages.item(): print (name.title()+ " 's favorite language is " +language.title()+ " . " )
The text editors we use generally use obvious colors as hints:
Modified code:
favorite_languages = { ' jen ' : ' python ' , ' sarah ' : ' c ' , ' edward ' : ' ruby ' , ' phil ' : ' python ' , } for name,language in favorite_languages.items(): print (name.title()+ " 's favorite language is " +language.title()+ " . " )
operation result:
1 Jen ' s favorite language is Python. 2 Sarah ' s favorite language is C. 3 Edward ' s favorite language is Ruby. 4 Phil ' s favorite language is Python. 5 Sarah ' s favorite language is C.
Summarize the commonly used Python error types as follows:
- ZeroDivisionError-divide (or modulo) zero (all data types)
- ValueError-Invalid parameter passed in
- AssertionError-assertion statement failed
- StopIteration-the iterator has no more values
- IndexError-there is no such index in the sequence (index)
- IndentationError-indentation error
- OSError-input/output operation failed
- ImportError——Failed to import module/object
- NameError-Object not declared/initialized (no attributes)
- AttributeError- indicating that the object does not have this attribute
- GeneratorExit-an exception occurs in the generator to notify the exit
- TypeError-invalid operation on the type
- KeyboardInterrupt-user interrupt execution (usually input ^C)
- OverflowError-Numerical operation exceeds the maximum limit
- FloatingPointError-floating point calculation error
- BaseException-the base class of all exceptions
- SystemExit-interpreter requests to exit
- Exception-the base class for general errors
- StandardError-the base class for all built-in standard exceptions
- ArithmeticError-the base class for all numerical calculation errors
- EOFError-there is no built-in input, reaching the EOF mark
- EnvironmentError-the base class for operating system errors
- WindowsError-system call failed
- LookupError-the base class for invalid data query
- KeyError-there is no such key in the map
- MemoryError-memory overflow error (not fatal to the Python interpreter)
- UnboundLocalError-access to uninitialized local variables
- ReferenceError-Weak reference attempts to access objects that have been garbage collected
- RuntimeError-general runtime error
- NotImplementedError-method not yet implemented
- SyntaxError Python-syntax error
- TabError-Tab and space are mixed
- SystemError-general interpreter system error
- UnicodeError-Unicode related errors
- UnicodeDecodeError-Unicode decoding error
- UnicodeEncodeError-Unicode encoding error
- UnicodeTranslateError-Unicode conversion error
The following are warning types
- Warning-the base class of warnings
- DeprecationWarning-warning about deprecated features
- FutureWarning-a warning that the semantics of the structure will change in the future
- OverflowWarning-old warning about automatic promotion to long integer (long)
- PendingDeprecationWarning-warning about the feature will be deprecated
- RuntimeWarning-warning of suspicious runtime behavior
- SyntaxWarning-warning of suspicious syntax
- UserWarning-warning generated by user code
Read More:
- How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’
- How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘
- [Solved] Python 3.6 Error: ‘dict’ object has no attribute ‘has_key’
- [Solved] TUM associate.py Scripte Error: AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘
- [Modified] AttributeError: ‘socket‘ object has no attribute ‘ioctl‘ python linux
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- [Solved] Python Keras Error: AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- Python Openyxl Error: AttributeError: ‘int‘ object has no attribute ‘upper‘ [How to Solve]
- [Solved] python Error: AttributeError: ‘NoneType‘ object has no attribute ‘split‘
- Python writes DICOM file (attributeerror: ‘filemetadataset’ object has no attribute ‘transfersyntax uid’ solution)
- [Solved] Python Selenium Error: AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_xpath‘
- [Solved] vpython: AttributeError: ‘box‘ object has no attribute ‘idx‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘