AttributeError: 'NoneType' object has no attribute 'append'
TL;DRThis Python error occurs when code tries to add an item to a list using append, but the variable holds None (nothing) instead of an actual list.
Most likely cause: A function or expression returned None and that value was stored in the variable used with append.
Try first: Find the exact line
Likely causes
- A function or expression returned None and that value was stored in the variable used with append.most likely
- The variable was never created or assigned a list before the append call.possible
- A conditional branch left the variable unset or set to None.less likely
How to fix it
Safest first: SafeChanges settingsDangerous
Find the exact lineSafe
Open the Python file and look for any line ending in .append( to identify where the error happens.
Check the variable valueSafe
Right before that line, add a temporary print statement to show what the variable actually contains.
Ensure a list is assignedChanges settings
Make sure the variable is set to an empty list [] or a returned list before any append is called.
If that didn't fix it
Run the script with a debugger or add more print statements around the failing line to trace the variable's value step by step.
When to see a technician
If this error appears in a larger application you did not write, ask the original developer or post the surrounding code on a programming forum.
Quick answers
- What does AttributeError: 'NoneType' object has no attribute 'append' mean?
- This Python error occurs when code tries to add an item to a list using append, but the variable holds None (nothing) instead of an actual list.
- What causes AttributeError: 'NoneType' object has no attribute 'append'?
- A function or expression returned None and that value was stored in the variable used with append. (most likely) The variable was never created or assigned a list before the append call. (possible) A conditional branch left the variable unset or set to None. (less likely)
- How do I fix AttributeError: 'NoneType' object has no attribute 'append'?
- Try these in order, safest first: 1. Find the exact line. 2. Check the variable value. 3. Ensure a list is assigned.
- What if that didn't fix it?
- Run the script with a debugger or add more print statements around the failing line to trace the variable's value step by step.
- When should I see a technician?
- If this error appears in a larger application you did not write, ask the original developer or post the surrounding code on a programming forum.
Related errors
codeTypeError: 'NoneType' object is not subscriptablecodeFileNotFoundError: [Errno 2] No such file or directory: 'config.json'codeModuleNotFoundError: No module named requestscodeObjects are not valid as a React child (found: object with keys {id, name}). If you meant to render a collection of chilcodenpm ERR! code ENOENT: no such file or directory, open 'package.json'codegyp ERR! find Python | gyp ERR! stack Error: Could not find any Python installation to use