import MySQLdb
class Db:
_db=-1
_cursor=-1
@classmethod
def __init__(self,s erver,user,pass word,database):
self._db=MySQLd b.connect(serve r , user , password , database)
self._cursor=se lf._db.cursor()
@classmethod
def excecute(self,c md):
self._cursor.ex ecute(cmd)
self._db.commit ()
@classmethod
def rowcount(self):
return int(self._curso r.rowcount)
@classmethod
def fetchone(self):
return self._cursor.fe tchone()
@classmethod
def close(self):
self._cursor.cl ose()
self._db.close( )
if __name__ == '__main__':
gert=Db('localh ost','root','** ****','gert')
gert.excecute(' select * from person')
for x in range(0,gert.ro wcount):
print gert.fetchone()
gert.close()
gert@gert:~$ python ./Desktop/svn/db/Py/db.py
Traceback (most recent call last):
File "./Desktop/svn/db/Py/db.py", line 35, in <module>
for x in range(0,gert.ro wcount):
TypeError: range() integer end argument expected, got instancemethod.
gert@gert:~$
Can anybody explain what i must do in order to get integer instead of
a instance ?
class Db:
_db=-1
_cursor=-1
@classmethod
def __init__(self,s erver,user,pass word,database):
self._db=MySQLd b.connect(serve r , user , password , database)
self._cursor=se lf._db.cursor()
@classmethod
def excecute(self,c md):
self._cursor.ex ecute(cmd)
self._db.commit ()
@classmethod
def rowcount(self):
return int(self._curso r.rowcount)
@classmethod
def fetchone(self):
return self._cursor.fe tchone()
@classmethod
def close(self):
self._cursor.cl ose()
self._db.close( )
if __name__ == '__main__':
gert=Db('localh ost','root','** ****','gert')
gert.excecute(' select * from person')
for x in range(0,gert.ro wcount):
print gert.fetchone()
gert.close()
gert@gert:~$ python ./Desktop/svn/db/Py/db.py
Traceback (most recent call last):
File "./Desktop/svn/db/Py/db.py", line 35, in <module>
for x in range(0,gert.ro wcount):
TypeError: range() integer end argument expected, got instancemethod.
gert@gert:~$
Can anybody explain what i must do in order to get integer instead of
a instance ?
Comment