Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64754 > unrolled thread

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

Started bylgabiot <lgabiot@hotmail.com>
First post2014-01-26 02:59 +0100
Last post2014-01-26 15:29 +0100
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Can't get sqlite3.Row working: keyword lookup doesn't work lgabiot <lgabiot@hotmail.com> - 2014-01-26 02:59 +0100
    Re: Can't get sqlite3.Row working: keyword lookup doesn't work Peter Otten <__peter__@web.de> - 2014-01-26 09:05 +0100
      Re: Can't get sqlite3.Row working: keyword lookup doesn't work lgabiot <lgabiot@hotmail.com> - 2014-01-26 15:29 +0100
      Re: Can't get sqlite3.Row working: keyword lookup doesn't work lgabiot <laurent.gabiot@gmail.com> - 2014-01-26 15:29 +0100

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

Fromlgabiot <lgabiot@hotmail.com>
Date2014-01-26 02:59 +0100
SubjectCan't get sqlite3.Row working: keyword lookup doesn't work
Message-ID<52e46bf3$0$2378$426a34cc@news.free.fr>
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.

[toc] | [next] | [standalone]


#64766

FromPeter Otten <__peter__@web.de>
Date2014-01-26 09:05 +0100
Message-ID<mailman.5990.1390723532.18130.python-list@python.org>
In reply to#64754
lgabiot wrote:

> 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',
[...]
> 'is_cantar', 'is_sound_devices', 'exist']
> 
> error =>  Index must be int or string

Please remember to cut and past the traceback next time.

> What is wrong?

My crystal ball says that you have a

from __future__ import unicode_literals

statement at the beginning of the module. If I'm right try

row[b"filename"]

[toc] | [prev] | [next] | [standalone]


#64774

Fromlgabiot <lgabiot@hotmail.com>
Date2014-01-26 15:29 +0100
Message-ID<52E51BB7.1020801@hotmail.com>
In reply to#64766
Le 26/01/14 09:05, Peter Otten a écrit :

> Please remember to cut and past the traceback next time.
>
>> What is wrong?
>
> My crystal ball says that you have a
>
> from __future__ import unicode_literals
>
> statement at the beginning of the module. If I'm right try
>
> row[b"filename"]


Thanks a lot for your answer!
your crystal ball was completely right, indeed I use the __future__ 
import, and the b'' fixed everything. Three days I was trying to get this...

[toc] | [prev] | [next] | [standalone]


#64795

Fromlgabiot <laurent.gabiot@gmail.com>
Date2014-01-26 15:29 +0100
Message-ID<mailman.6003.1390769554.18130.python-list@python.org>
In reply to#64766
Le 26/01/14 09:05, Peter Otten a écrit :

> Please remember to cut and past the traceback next time.
>
>> What is wrong?
>
> My crystal ball says that you have a
>
> from __future__ import unicode_literals
>
> statement at the beginning of the module. If I'm right try
>
> row[b"filename"]


Thanks a lot for your answer!
your crystal ball was completely right, indeed I use the __future__ 
import, and the b'' fixed everything. Three days I was trying to get this...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web