Re: instancemethod
- From: "Gabriel Genellina" <gagsl-py@xxxxxxxxxxxx>
- Date: Sun, 21 Jan 2007 21:37:57 -0300
"Gert Cuykens" <gert.cuykens@xxxxxxxxx> escribió en el mensaje news:ef60af090701211416n5b2eb7edt2ee6d4555bd49c1a@xxxxxxxxxxxxxxxxx
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
.
- Prev by Date: Re: Python Windows Editors
- Next by Date: Re: Beginners Tutorial in PDF Format?
- Previous by thread: Re: instancemethod
- Next by thread: Re: instancemethod
- Index(es):
Relevant Pages
|