diff options
author | TinWoodman92 <chrhodgden@gmail.com> | 2022-11-27 19:30:52 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 19:30:52 -0600 |
commit | f841f66799eeafb407f8b10c630dae2d1987c345 (patch) | |
tree | e03c3364da673b17f0e90463fcc4eef420e7da25 | |
parent | 591b1ed6237f250e60eaef321ab9fe0f93c070a0 (diff) | |
parent | ab7b44d43707b189bd0947abd9033e062b00a825 (diff) |
Merge pull request #1 from TinWoodman92/use_fetchone
Use .fetchone() for single result query.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | hw.py | 7 |
2 files changed, 4 insertions, 4 deletions
@@ -1,3 +1,4 @@ *.db +*.db-journal *demo* *test*
\ No newline at end of file @@ -15,16 +15,14 @@ if chk_1: cur.execute("CREATE TABLE sexy_tbl (chk INTEGER);") chk_2 = randint(0,1) - cur.execute("INSERT INTO sexy_tbl (chk) VALUES(:chk);", {"chk" : chk_2}) -rst = [] k = [] res = cur.execute("SELECT sum(chk) as sum_chk, count(chk) as count_chk FROM sexy_tbl;") for desc in cur.description: k.append(desc[0]) -for row in res.fetchall(): rst.append(dict(zip(k,row))) +row = res.fetchone() +rcd = dict(zip(k,row)) -rcd = rst[0] chk_3 = (rcd["sum_chk"]/rcd["count_chk"]) > 0.5 if chk_3: @@ -36,6 +34,7 @@ diag = input() if 'sexy' in diag.lower(): print(f"Your sexy score is {rcd['sum_chk']} out of {rcd['count_chk']}.") + input() con.commit() cur = None |