From 201d2d4a65355dc4b672c5f7d67c7a7cd0b9180e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Tue, 15 Jan 2019 12:43:51 +0100 Subject: [PATCH] Rewrite get_data, unnecessary Python data processing --- ib-clearance.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ib-clearance.py b/ib-clearance.py index f41528e..3168767 100755 --- a/ib-clearance.py +++ b/ib-clearance.py @@ -49,16 +49,20 @@ def get_data(conn): id = int(input("\nPlease enter student ID: ")) cur = conn.cursor() - cur.execute("SELECT id, student_class, other FROM students") - ids = cur.fetchall() # ids is list of tuples. + cur.execute(""" + SELECT id, student_class, other + FROM students + WHERE id = ? + """, (id,)) + data = cur.fetchone() - for tup in ids: - if id == tup[0]: - lis = list(tup) - lis[2] = lis[2].split() - return lis + if data is not None: + data = list(data) # SQLite returns tuples. + data[2] = data[2].split() else: raise ValueError + + return data except ValueError: print("\nInvalid ID, try again.") return get_data(conn)