I've been battling with this one for hours. I'm a relative Python newbie, but I do have some coding experience.
For clarity, I'll trim the connection stuff. I'm trying to do a lookup to get a number from one of my tables based on a given string (retrieved from a CSV file), something like:
SELECT = 'select industry_group_num from tbl_INDUSTRY_GROUP where industry_group_name = ' + `IndGroupName` + ';'
This works, as long as there is a matching industry_group_name in the table. Where I am running into problems is when there isn't one -- according to the specs, sqlite3 returns None, which I understand is basically a Python Null type.
Here's my supposed error catcher:
result = cursor.execute(SELECT) if result.fetchone() is None: print 'Empty' else: var = result.fetchone() print var
I have tried every variation I can think of for that if statement, but I always get this error from Python:
TypeError: 'NoneType' object is unsubscriptable
I figure that means that the None type is not a tuple and cannot be iterated through using [n] notation. But I can't figure out the solution!
Any and all help is appreciated. I hope that there's enough information; please let me know if there isn't.