Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 520 Bytes

File metadata and controls

33 lines (23 loc) · 520 Bytes

AttributeError: 'NoneType' object has no attribute 'split'

I tried to call .split() on a variable that was None.

reproduce.py

username = None
parts = username.split("_")
print(parts)

Error message

AttributeError: 'NoneType' object has no attribute 'split'

fix.py

username = None

if username is None:
    print("Username not available")
    username = ""

parts = username.split("_")
print(parts)

Reflection

Forgot to check for None before calling a method.