Can't get sqlite3.Row working: keyword lookup doesn't work

lgabiot lgabiot at hotmail.com
Sat Jan 25 20:59:14 EST 2014


Hello,

using Python 2.7.6

I try to access a sqlite database using keyword lookup instead of 
position (much more easy to maintain code), but it always fail, with the 
error:
Index must be int or string

I have created the database, populated it, and here is the code that 
tries to retrieve the information:

with sqlite3.connect(mydbPath) as db: # open the database
     db.row_factory = sqlite3.Row
     cursor = db.cursor()
     cursor.execute("SELECT * FROM files")

     for row in cursor.fetchall():
         print(row.keys())
         print(row["filename"])


result is:

['filename', 'filepath', 'filetag', 'PROJECT', 'SCENE', 'TAKE', 'TAPE', 
'CIRCLED', 'FILE_UID', 'UBITS', 'TOTAL_FILES', 'FAMILY_UID', 'track_1', 
'track_2', 'track_3', 'track_4', 'track_5', 'track_6', 'track_7', 
'track_8', 'track_9', 'track_10', 'track_11', 'track_12', 'NOTE', 
'duration', 'BWF_ORIGINATION_DATE', 'TIMECODE_FLAG', 'TIMECODE_RATE', 
'FILE_SAMPLE_RATE', 'AUDIO_BIT_DEPTH', 'DIGITIZER_SAMPLE_RATE', 
'TIMESTAMP_SAMPLE_RATE', 'TIMESTAMP_SINCE_MIDNIGHT', 'is_Short', 
'is_MS', 'is_renamed_MS', 'WF_created', 'max_level', 'is_silent', 
'is_silent_moved', 'silent_path', 'is_WS', 'is_WS_copied', 'CSV_made', 
'is_cantar', 'is_sound_devices', 'exist']

error =>  Index must be int or string

What is wrong?

thanks a lot.



More information about the Python-list mailing list