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

Mats Wichmann mats at wichmann.us
Thu Jan 6 16:21:48 EST 2022


On 1/6/22 11:02, Kushal Kumaran wrote:
> On Tue, Jan 04 2022 at 11:34:20 PM, NArshad <narshad.380 at gmail.com> wrote:
>> How to correct what is written below:
>>
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>>   File "C:\Users\Dani Brothers\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
>>     return self.func(*args)
>>   File "D:/Python/Book Bank/New folder/PyCharm/Final/Excel.py", line 57, in SaveBook
>>     e_pissue.get(),
>> AttributeError: 'NoneType' object has no attribute 'get'
>>
>> Process finished with exit code 0
> 
> The error means that e_pissue is None, so your code cannot call the get
> method on it.  You need to fix the code so that e_pissue is not None and
> is instead referring to an object that has a suitable get method.


And at a more meta level:  many functions in the Python world return
None as an indication that the operation did not succeed.  It's useful
because in many circumstances None is an "out of band" value - one that
could not happen naturally - and thus returning it provides an easy way
for the caller to check for success or failure.

However... if that is the case, you have to actually do that check.  If
you just proceed as if a vaild value had come back, you're defeating the
purpose - and are sure to fall into a hole like the one you've encountered.


More information about the Python-list mailing list