[Tutor] Module? Error handling specific to SQLite3

Paul Smith paulrsmith7777 at gmail.com
Fri Sep 26 19:25:53 CEST 2014


Ok Tutor help please...

Early stages messing with module sqlite3 in python3.4. I am successful in
creating sqlite tables of my own and interacting with other sqlite tables,
however in refining the code from a purely "it can do it" stage to a more
stable working piece of code I run into this problem.

I call the correct sqlite3 items and create table D to which I add or
'amend' specific information from tables A and Z.

However since the table is already created the line of code that created
the table subsequently kicks out this error when the program runs again.

Traceback (most recent call last):
  File "C:\Users\Thechives\Desktop\pyweather\AlphaItems\
weathercodetrial1.2.py", line 206, in <module>
    cur.execute('''CREATE TABLE "D" AS SELECT weather_current FROM
"todays_weather" WHERE weather_current IS NOT NULL''')
sqlite3.OperationalError: table "D" already exists

So how does one handle the error or ignore the creation portion of the
program once the table is created?

Python exception handling has not helped, Try - Except - although I am
mashing it I am sure. I believe since we are actually engaging sqlite via
python at this point in the code it should be a sqlite error handler or
some such. So simple and yet it eludes my noobile mind.

Thanks in advance,

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140926/eaf06916/attachment.html>


More information about the Tutor mailing list