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

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

I keep getting an error that says

AttributeError: \'NoneType\' object has no attribute \'something\'
相关标签:
10条回答
  • 2020-11-21 13:55

    The NoneType is the type of the value None. In this case, the variable lifetime has a value of None.

    A common way to have this happen is to call a function missing a return.

    There are an infinite number of other ways to set a variable to None, however.

    0 讨论(0)
  • 2020-11-21 13:58

    You can get this error with you have commented out HTML in a Flask application. Here the value for qual.date_expiry is None:

       <!-- <td>{{ qual.date_expiry.date() }}</td> -->
    

    Delete the line or fix it up:

    <td>{% if qual.date_attained != None %} {{ qual.date_attained.date() }} {% endif %} </td>
    
    0 讨论(0)
  • 2020-11-21 14:01

    if we assign something like the below, it will throw error as "AttributeError: 'NoneType' object has no attribute 'show'"

    df1=df.withColumn('newAge',df['Age']).show() 
    
    0 讨论(0)
  • 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'

    0 讨论(0)
提交回复
热议问题