O
O
OlegUnity2020-07-15 13:58:35
Python
OlegUnity, 2020-07-15 13:58:35

TypeError: 'NoneType' object is not subscriptable SQlite 3 (1,) What's the problem?

def license(ID):
  try:
    lock.acquire(True)
    sql.execute(f"SELECT LIC FROM users WHERE ID = '{ID}'")
    #print(sql.fetchone())
    if print(sql.fetchone()) == None:
      return 0#Нет ЛИЦ
    elif print(sql.fetchone()[0]) == 1:
      print('da')
      return 1#Есть ЛИЦ
    else:
      return 0#Нет ЛИЦ
  finally:
    lock.release()

I do a check, but it wasn’t there, it writes this:
elif print(sql.fetchone()[0]) == 1:
TypeError: 'NoneType' object is not subscriptable
But if without [0], then it stupidly does not see the number 1. How to figure it out?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-07-15
@OlegUnity

Reading the documentation :

Fetches the next row of a query result set, returning a single sequence, or None when no more data is available.

That is, the first call fetchoneto if print(sql.fetchone()) == None:returns a result, but the second elif print(sql.fetchone()[0]) == 1:does not.

D
datasciencetraining, 2020-09-10
@datasciencetraining

Visit ti know more for above information: typeerror nonetype object is not subscriptable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question