Problem with sqlite

aiwarrior zubeido at yahoo.com.br
Sun Mar 30 10:44:31 EDT 2008


Ok regarding Gerhard's comment of the try, except, pass, i came to
understand that it's really bad code. And i should have referred that
i put that there be cause i was getting:

Traceback (most recent call last):
  File "C:\Python25\Projects\cp.py", line 48, in <module>
    db = db()
  File "C:\Python25\Projects\cp.py", line 19, in __init__
    self.cursor.execute( "CREATE TABLE database (album,filepath)" )
OperationalError: table database already exists


But when i tried to handle the Operational error with :

        try:
            self.cursor.execute( "CREATE TABLE database
(album,filepath)" )
        except OperationalError:
            pass

I would got:
NameError: global name 'OperationalError' is not defined

I searched the Internet and found that sqlite3.OperationalError was
missing. Dumb me.

Now even though i've been reading a bit about exceptions in python
tutorial i've come to realize that my approach won't give me the
results i want.
To my understanding the try statement will still execute the statement
within it until it produces the error. So even if i caught this
OperationalError i wouldn't know what to do with it.

What i'm going to study is whether it's possible to evaluate if a
table already exists, and if so act accordingly.

Duncan Booth wrote:
>Are you absolutely certain of that? If you use print to try to debug the
>value of an object you should usually use repr
>                print repr(audio['album'])


As Gerhard correctly guessed i'm a newbie and didn't know of the
existence repr. I've been reading about it in python documentation but
have yet to analyze it more carefully.

I guess the parentheses are just some form of maniac stupidity. Will
try to be more clean about them.

Thanks for all the patience and hope i've been more forthcoming in
this post.



More information about the Python-list mailing list