TypeError: 'NoneType' object has no attribute '__getitem__' whereas cur.fetchone is not None
python, sqlite
Solution
`fetchone` fetches the data and changes state of `cursor` object, i.e. if there was only one row to fetch, next call to `fetchone` will return `None`.
Try the next:
cur1.execute("SELECT * FROM consommation WHERE zone=? AND date=?", (zone, date_p))
res = cur1.fetchone()
if res:
abcisses += (res[0][11:13] + 'h',)
Problem
I have the following code : ``` cur1.execute("SELECT * FROM consommation WHERE zone=? AND date=?",(zone,date_p)) if cur1.fetchone() is not None: abcisses+=(cur1.fetchone()[0][11:13]+'h',) ``` but when I run it I have an error : `TypeError: 'NoneType' object has no attribute '__getitem__'`, whereas cur1.fetchone is not empty. So I don’t understand why it doesn’t work. Is there someone who know why ?