-2

I want to get the integer 5 from my database but I keep getting "[('5',)]" or "('5',)" this is my code:

import sqlite3

db = sqlite3.connect("Users.db")
cursor = db.cursor()

def get_clearance(username='CC-2225', clearance=None):
        find_clearance = "SELECT clearance FROM user WHERE username = username"
        cursor.execute(find_clearance)
        results = cursor.fetchall()
        return results

print(get_clearance())
fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
Noa
  • 3
  • 1
  • 2

1 Answers1

0

It is not uncommon for database API to return list or tuples.

A simple solution would be to cast this value directly to integer, if you are sure it will always be an integer:

For the list of tuples ("[('5',)]"):

return int(results[0][0])

For the tuple ("('5',)"):

return int(results[0])
Itération 122442
  • 2,644
  • 2
  • 27
  • 73