Why do I get AttributeError: 'NoneType' object has no attribute 'something'?

前端 未结 10 2021
长情又很酷
长情又很酷 2020-11-21 13:36

I keep getting an error that says

AttributeError: \'NoneType\' object has no attribute \'something\'
10条回答
  •  情深已故
    2020-11-21 14:07

    You have a variable that is equal to None and you're attempting to access an attribute of it called 'something'.

    foo = None
    foo.something = 1
    

    or

    foo = None
    print(foo.something)
    

    Both will yield an AttributeError: 'NoneType'

提交回复
热议问题