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

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

I keep getting an error that says

AttributeError: \'NoneType\' object has no attribute \'something\'
10条回答
  •  忘了有多久
    2020-11-21 13:52

    It means the object you are trying to access None. None is a Null variable in python. This type of error is occure de to your code is something like this.

    x1 = None
    print(x1.something)
    
    #or
    
    x1 = None
    x1.someother = "Hellow world"
    
    #or
    x1 = None
    x1.some_func()
    
    # you can avoid some of these error by adding this kind of check
    if(x1 is not None):
        ... Do something here
    else:
        print("X1 variable is Null or None")
    

提交回复
热议问题