How to fix AttributeError: 'list' object has no attribute 'method' in Python

PythonBEGINNERMEDIUMUpdated Dec 7, 2025ยท 153 views

This error occurs when trying to access a method or property that doesn't exist on an object. Common causes include typos, using outdated library versions, or objects being None when you didn't expect.

Quick fix

Fixes AttributeError: 'list' object has no attribute 'method'

obj = some_object()
print(dir(obj))  # List all attributes
print(hasattr(obj, 'attribute_name'))  # Check if specific attribute exists
  1. Check if attribute exists
  2. Check the library version
  3. Fix typos
  4. Check for None values
python โ€” error
obj = some_object()
print(dir(obj)) # List all attributes
print(hasattr(obj, 'attribute_name')) # Check if specific attribute exists
AttributeError: 'list' object has no attribute 'method'

What this error means

The "AttributeError: 'X' object has no attribute 'Y'" error means you tried to access a method or property 'Y' on an object of type 'X' that doesn't have it. Common causes: 1. **Typo**: Misspelled method or property name 2. **API Changed**: Library update removed or renamed the attribute 3. **Wrong Object Type**: Object is different type than expected (e.g., None instead of a dict) 4. **Old Library Version**: Using old API that changed in newer version 5. **Conditional Logic**: Object sometimes is None or a different class This is caught at runtime, so it often appears in production if code paths aren't well tested.

Typical symptoms

  • AttributeError: 'X' object has no attribute 'Y'
  • Works with one library version but not another
  • Code fails at runtime but not during syntax checking

Common causes

  1. Accessing attribute that doesn't exist on the object
  2. Method or property removed in newer library version
  3. Object is None or different type than expected
  4. Typo in attribute or method name
  5. Using old API that changed in new library version

How to fix "AttributeError: 'list' object has no attribute 'method'"

1Check if attribute exists

Use Python's dir() and hasattr():

python
obj = some_object()
print(dir(obj))  # List all attributes
print(hasattr(obj, 'attribute_name'))  # Check if specific attribute exists
2Check the library version

See what version of the library is installed:

bash
pip show package-name

Check the library's changelog for API changes.

3Fix typos

Verify the attribute name is spelled correctly:

python
# Correct
obj.some_method()  # vs obj.somemethod()
obj.property_name  # vs obj.propertyname
4Check for None values

Ensure your object is not None:

python
if obj is not None:
    obj.method()
else:
    print("Object is None")
5Update the library

If using old code with new library, update:

bash
pip install --upgrade package-name

Then check the documentation for API changes.

Advanced notes

Use type hints and an IDE with autocomplete to catch attribute errors during development rather than at runtime.

Frequently asked questions

What does "AttributeError: 'list' object has no attribute 'method'" mean?
The "AttributeError: 'X' object has no attribute 'Y'" error means you tried to access a method or property 'Y' on an object of type 'X' that doesn't have it. Common causes: 1. Typo: Misspelled method or property name 2.
How do I fix "AttributeError: 'list' object has no attribute 'method'"?
This error occurs when trying to access a method or property that doesn't exist on an object. Common causes include typos, using outdated library versions, or objects being None when you didn't expect.
What causes "AttributeError: 'list' object has no attribute 'method'"?
Accessing attribute that doesn't exist on the object Method or property removed in newer library version Object is None or different type than expected
Is the "AttributeError: 'list' object has no attribute 'method'" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading