Nro
Nro

Reputation: 349

Can't compare and print SQL result in Python

I need help with this simple yet important for me task. I have the following code, where I am trying to extract id from a table, then compare it to a number, then simply print it.

track_id=cur.execute("SELECT id FROM files WHERE track_title='re.mp3';")

self.assertEqual(track_id, "2")

print track_id

I get an error because track_id returns 'none'

Upvotes: 0

Views: 48

Answers (1)

chishaku
chishaku

Reputation: 4643

cur.execute("SELECT id FROM files WHERE track_title='re.mp3';")
track_id = cur.fetchone()[0]

Upvotes: 1

Related Questions