[DB-SIG] new to list - subclass of 'MySQLdb'??

Denis S. Otkidach ods at strana.ru
Wed Nov 19 11:39:15 EST 2003


On Wed, 19 Nov 2003, Hardy Merrill wrote:

HM> I thought I'd try to find or write a database independent
HM> layer so that I could do something like
HM>
HM>    MyDB.py
HM>    -------
HM>    #!/usr/bin/python
HM>
HM>    import MySQLdb
HM>
HM>    class MyDB(MySQLdb):
HM>        def __init__(self):
HM>            MySQLdb.__init__(self)
HM>
HM>    test.py
HM>    -------
HM>    #!/usr/bin/python
HM>    import MyDB

You should use "from MyDB import MyDB" instead.

HM>    mydb = MyDB()
HM>    conn = MyDB.connect(db="mydatabase", user="myuser",
HM> passwd="mypass")
HM>
HM> to make the code more generic and more portable if I were
HM> to change the database in the future.
HM>
HM> This doesn't work - when I run test.py I get this error:
HM>
HM>    [hmerrill at merrill mysqldb]$ ./test.py
HM>    Traceback (most recent call last):
HM>      File "./test.py", line 3, in ?
HM>        mydb = MyDB()
HM>    TypeError: 'module' object is not callable
HM>
HM> Am I doing this wrong?  How *should* I be doing this?
HM> Anyone

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]




More information about the DB-SIG mailing list