instancemethod [英] instancemethod

查看:80
本文介绍了instancemethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入MySQLdb

类Db:


_db = -1

_cursor = -1


@classmethod

def __init __(self,server,user,password,database):

self._db = MySQLdb.connect(服务器,用户,密码,数据库)

self._cursor = self._db.cursor()


@classmethod

def excecute(self,cmd):

self._cursor.execute(cmd)

self._db.commit()


@classmethod

def rowcount(self):

return int(self._cursor.rowcount)


@classmethod
def fetchone(个体经营):

返回self._cursor.fetchone()


@classmethod

def关闭(个体经营):

self._cursor.close()

self._db.close()


if __name__ = =''__ main__'':

gert = Db(''localhost'',''root'',''******'',''gert'')

gert.excecute(''select * from person'')

for x in range(0,g ert.rowcount):

print gert.fetchone()

gert.close()


gert @ gert:〜$ python ./Desktop/svn/db/Py/db.py

Traceback(最近一次调用最后一次):

文件" ./ Desktop / svn / db / Py /db.py" ;,第35行,在< module>

for x in range(0,gert.rowcount):

TypeError:range()整数结束参数预期,得到了实例方法。

gert @ gert:〜$


任何人都可以解释我必须做什么才能得到整数而不是

a实例?

解决方案

python ./Desktop/svn/db/Py/db.py

Traceback(最近的电话最后一次):

文件" ./ Desktop / svn / db / Py / db.py",第35行,< module>

for x在范围(0,gert.rowcount)中:

TypeError:range()期望整数结束参数,得到instancemethod。

gert @ gert:〜





任何人都可以解释我必须做什么才能得到整数实例?


>


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()


gert @ gert :〜

import MySQLdb

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()

@classmethod
def rowcount(self):
return int(self._cursor.rowcount)

@classmethod
def fetchone(self):
return self._cursor.fetchone()

@classmethod
def close(self):
self._cursor.close()
self._db.close()

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()

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.rowcount):
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 ?

解决方案

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.rowcount):
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 ?


>

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()

gert@gert:~


这篇关于instancemethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆