I find this code to be very readable.

I, personally, would not use quite so much vertical white space, like whole
lines with only a "(", but that is a matter of aesthetics only. My senses
were probably permanently marred by learning to program using punched cards
and 14 7/8 inch printer paper. Vertical space killed trees back then. Also,
for production code, I would specify the exceptions I expect to catch in the
try: except, and then re-raise the same exception. Always raising IOERROR
may lead one astray from finding the actual cause of the error.  These are
small things.

Your program is not only correct, it's also beautiful.
--
Vernon

On Sun, Nov 21, 2010 at 1:02 PM, John Q. Public <sqlite3.u...@gmail.com>wrote:

>
> Is this how my createdb() method should look like?
> How would you write this method so it is both readable and correct?
> Thank you for your time and patience.
>
> def createdb(self):
>    try:
>        con = sqlite3.connect(db)
>        cur = con.cursor()
>
>        cur.execute('''
>            CREATE TABLE t1
>            (
>                kid INTEGER PRIMARY KEY,
>                c1 TEXT,
>                c2 TEXT
>            )
>        ''')
>
>        cur.execute('''
>            CREATE TABLE t2
>            (
>                kid INTEGER PRIMARY KEY,
>                c1 TEXT,
>                c2 TEXT
>            )
>        ''')
>
>        cur.execute('''
>            CREATE TABLE t3
>            (
>                kid INTEGER PRIMARY KEY,
>                c1 TEXT,
>                c2 TEXT
>            )
>        ''')
>
>        con.commit()
>    except:
>        a = "ERROR: createdb did not commit. \n"
>        b = "tried this sql:   \n"
>        raise IOError, "%s%s%s" % ( a, b, sql )
>    finally:
>        cur.close()
>        con.close()
>
> --
> View this message in context:
> http://old.nabble.com/Python-db-programming-conventions-tp29977345p30273508.html
> Sent from the Python - db-sig mailing list archive at Nabble.com.
>
> _______________________________________________
> DB-SIG maillist  -  DB-SIG@python.org
> http://mail.python.org/mailman/listinfo/db-sig
>
_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

Reply via email to