Error when configuring tkinter widget: 'NoneType' object has no attribute
NoneType object has no attribute ...
means that you have an object that is None
, and you're trying to use an attribute of that object.
In your case you're doing q.get(...)
, so q
must be None
. Since q
is the result of calling nse.get_quote(...)
, that function must have the possibility of returning None
. You'll need to adjust your code to account for that possibility, such as checking the result before trying to use it:
q = nse.get_quote(stock)
if q is not None:
print ...
The root of the problem is likely in how you're reading the file. stock
will include the newline, so you should strip that off before calling nse.get_quote
:
q = nse.get_quote(stock.strip())