deriving MySQLdb class

Sean DiZazzo half.italian at
Fri Jan 22 04:42:35 CET 2010

On Jan 21, 5:48 pm, tekion <tek... at> wrote:
> All,
> I am trying to write a class which inherits from MySQLdb class.  Below
> is code snippet:
> import MySQLdb
> import sys
> class  msql_connect(MySQLdb):
>     def __init__(self):
>     =  "hostname"
>         self.user     = "user"
>         self.password  = "passoword"
>         self.database = "database name"
> I am running into below error:
>  class  msql_connect(MySQLdb):
> TypeError: Error when calling the metaclass bases
>     module.__init__() takes at most 2 arguments (3 given)
> Does any one have an idea why?  Thanks.

MySQLdb is the name of the module, not the class you want to
subclass.  But MySQLdb.connect() is not the class's a
factory function that returns instances of the class you actually want
to subclass...connections.Connection().  The below works for me.

from MySQLdb import connections
import sys

class  mysql_connect(connections.Connection):
    def __init__(self):     =  "host"
        self.user     = "user"
        self.password  = "password"
        self.database = "database"
user=self.user, passwd=self.password, db=self.database)

p = mysql_connect()


More information about the Python-list mailing list