Editor

AttributeError: 'list' object has no attribute

What it means

You called a method that lists do not have. Often the method belongs to the items inside the list, like split() or lower() on strings, so you need to call it on each item. The name at the end of the message is the method you tried.

1. Calling a string method on a whole list

This raises the error

Broken
lines = ['Ana,90', 'Ben,85']
parts = lines.split(',')
print(parts)
Output
Traceback (most recent call last):
  File "<exec>", line 2, in <module>
AttributeError: 'list' object has no attribute 'split'

The fix

Fixed
lines = ['Ana,90', 'Ben,85']
for line in lines:
parts = line.split(',') # split each string, one at a time
print(parts)
Output
['Ana', '90']
['Ben', '85']

split() belongs to strings, and lines is a list of strings. Loop over the list, or use a comprehension like [line.split(',') for line in lines].

Try fixing it yourself in the editor

2. Using method names from another language

This raises the error

Broken
nums = [1, 2, 3]
nums.push(4)
print(nums.length)
Output
Traceback (most recent call last):
  File "<exec>", line 2, in <module>
AttributeError: 'list' object has no attribute 'push'

The fix

Fixed
nums = [1, 2, 3]
nums.append(4) # Python's name for push
print(len(nums)) # length is a function, not an attribute
Output
4

Python lists use append() to add an item and the len() function for their size. JavaScript's push() and .length do not exist here.

Try fixing it yourself in the editor

3. A list of dictionaries treated as one dictionary

This raises the error

Broken
people = [{'name': 'Ana'}, {'name': 'Ben'}]
print(people.get('name'))
Output
Traceback (most recent call last):
  File "<exec>", line 2, in <module>
AttributeError: 'list' object has no attribute 'get'

The fix

Fixed
people = [{'name': 'Ana'}, {'name': 'Ben'}]
print(people[0].get('name'))
for person in people:
print(person.get('name'))
Output
Ana
Ana
Ben

.get() belongs to each dictionary, not to the list holding them. Pick one with people[0], or loop over them.

Try fixing it yourself in the editor

When you see this error, check

  • Print the variable and its type() to confirm it is a list.
  • Run print(dir([])) to see every method a list has.
  • If the method belongs to the items, call it inside a loop or a comprehension.
  • Check whether a function like split() or re.findall() already turned your value into a list.

All Python errors · How to read a traceback · Step through your code