AttributeError: object has no attribute (Fix)

This error happens when Python finds the object before the dot, but cannot find the attribute or method after the dot.

In simple terms:

  • The variable exists
  • But that kind of object does not have the thing you tried to use

For example, a list has append(), but an integer does not. A string has upper(), but a list does not.

If you are not sure what value you actually have, start by checking its type with type().

Quick fix #

name = "Python"
print(name.upper())   # correct: strings have upper()

numbers = [1, 2, 3]
print(numbers.append(4))  # correct: lists have append()

value = None
# print(value.append(1))  # wrong: None has no append()

Check the real type of the value with print(type(value)) and confirm that the attribute or method exists for that type.

What this error means #

AttributeError means Python could not find the attribute or method after the dot.

An attribute is something attached to an object, such as:

  • A value
  • A method
  • A property

Examples:

  • Strings have methods like upper() and split()
  • Lists have methods like append() and sort()
  • Dictionaries have methods like keys() and get()

This works:

text = "hello"
print(text.upper())

Output:

HELLO

But this fails because a list does not have upper():

items = ["a", "b", "c"]
print(items.upper())

Output:

AttributeError: 'list' object has no attribute 'upper'
Traceback (most recent call last):File "example.py", line 2, in <module>print(items.upper())AttributeError: 'list' object has no attribute 'upper'Where it happened — file and lineWhat went wrong — the exception typeWhy — the detailed message
Read it bottom-up: the last line names the object type (list) and the attribute it lacks (upper).

Why this happens #

This error usually appears for one of these reasons:

  • You used a method that belongs to a different type
  • A variable contains a different value than you expected
  • A function returned None, but you treated it like a list, string, or dictionary
  • There is a spelling mistake in the attribute name
  • You expected a module, class, or object to provide something that it does not

Common examples:

  • Calling a list method on a string or tuple
  • Calling a string method on a list
  • Using the result of print(), sort(), or append() as if it were a new object
  • Trying to use methods on None
  • Misspelling a method name
  • Confusing module names, class names, and instance methods

If you want a broader introduction to Python exceptions, see Python errors and exceptions explained.

Example that causes the error #

Using a string method on a list #

words = ["python", "is", "fun"]
print(words.upper())

This fails because upper() is a string method, not a list method.

Calling append() on None #

value = None
value.append(1)

This fails because None does not have an append() method.

A common reason is that a function returned None and you used it as if it were a list:

numbers = [3, 1, 2]
result = numbers.sort()

print(result)
print(result.append(4))

Output:

None
AttributeError: 'NoneType' object has no attribute 'append'

list.sort() changes the list in place and returns None.

Misspelling an attribute name #

name = "Python"
print(name.uper())

This fails because the method name is upper(), not uper().

Python method names are case-sensitive, so spelling and capitalization both matter.

How to fix it #

Here are the most useful ways to fix this error.

1. Check the object type #

Use type() to see what the value really is:

value = ["a", "b", "c"]
print(type(value))

Output:

<class 'list'>

If the type is not what you expected, trace back to where that value came from.

2. Print the value before the failing line #

Sometimes the variable changed earlier in the program.

result = None
print(result)
print(type(result))

This helps you confirm what Python is actually working with.

3. Inspect available attributes with dir() #

You can use dir() to list what an object supports:

text = "hello"
print(dir(text))

This can help you check whether a method really exists.

4. Check function return values before chaining methods #

Some methods return a new object. Others change the original object and return None.

Bad example:

numbers = [3, 1, 2]
result = numbers.sort()
print(result.append(4))

Correct version:

numbers = [3, 1, 2]
numbers.sort()
numbers.append(4)
print(numbers)

Output:

[1, 2, 3, 4]

5. Use the right method for the object type #

Wrong:

items = ["a", "b", "c"]
items.upper()

Correct:

items = ["a", "b", "c"]
upper_items = [item.upper() for item in items]
print(upper_items)

Output:

['A', 'B', 'C']

6. Fix spelling mistakes #

Wrong:

text = "hello"
print(text.uppr())

Correct:

text = "hello"
print(text.upper())

Output:

HELLO

Common beginner cases #

AttributeError: 'NoneType' object has no attribute ... #

This usually means your variable is None.

Common causes:

  • A function did not return a value
  • You used the result of append(), sort(), or print()
  • A value was set to None earlier

For a more focused guide, see AttributeError: ‘NoneType’ object has no attribute.

AttributeError: 'list' object has no attribute ... #

This means you called a method that lists do not support.

Example:

items = ["a", "b"]
print(items.split(","))

split() is a string method, not a list method.

See also AttributeError: ’list’ object has no attribute.

AttributeError: 'str' object has no attribute ... #

This means you used a method that belongs to some other type.

Example:

name = "Python"
name.append("!")

Strings do not have append().

See also AttributeError: ‘str’ object has no attribute.

AttributeError when importing a module and calling the wrong name #

Sometimes the object is a module, but the attribute name is wrong.

Example:

import math

print(math.PI)

This fails because the correct name is math.pi.

Correct version:

import math

print(math.pi)

Output:

3.141592653589793

Step-by-step debugging checklist #

When you see this error, work through these steps:

  1. Find the line named in the traceback
  2. Look at the value before the dot
  3. Print type(value)
  4. Check whether that type supports the attribute
  5. Trace back where the value came from
  6. Confirm the function or method returned what you expected

Useful debugging commands:

print(value)
print(type(value))
print(dir(value))
help(type(value))

If you want a beginner-friendly process for debugging, read the beginner guide to debugging Python code.

FAQ #

What is an attribute in Python? #

An attribute is something attached to an object, such as a variable or method. You access it with dot notation like obj.name or obj.method().

Why do I get this error with None? #

Because None is a special value, and many methods like append() or split() do not exist on it. Often a function returned None instead of the value you expected.

How do I know which methods an object has? #

Use dir(obj) to list available attributes and methods, or check the official documentation for that object type.

Is this the same as NameError? #

No. NameError means Python does not know the variable name at all. AttributeError means the variable exists, but the attribute after the dot does not.

See also #

Press Esc to close