instancemethod

Gabriel Genellina gagsl-py at yahoo.com.ar
Sun Jan 21 19:37:57 EST 2007


"Gert Cuykens" <gert.cuykens at gmail.com> escribió en el mensaje 
news:ef60af090701211416n5b2eb7edt2ee6d4555bd49c1a at mail.gmail.com...

> class Db:
>
>    _db=-1
>    _cursor=-1
>
>    @classmethod
>    def __init__(self,server,user,password,database):
>        self._db=MySQLdb.connect(server , user , password , database)
>        self._cursor=self._db.cursor()
>
>    @classmethod
>    def excecute(self,cmd):
>        self._cursor.execute(cmd)
>        self._db.commit()
>
>
> if __name__ == '__main__':
>    gert=Db('localhost','root','******','gert')
>    gert.excecute('select * from person')
>    for x in range(0,gert.rowcount):
>        print gert.fetchone()
>    gert.close()

Besides your specific question that was already answered, why are you using 
classmethods at all?
You are constructing a Db instance and using it as if all were normal 
instance methods... Just remove all those @classmethod declarations and use 
it in a standard way.

-- 
Gabriel Genellina 





More information about the Python-list mailing list