使用Python和游标获取属性错误
我使用的是posgres,python和游标。这是我的密码使用Python和游标获取属性错误,python,postgresql,cursor,Python,Postgresql,Cursor,我使用的是posgres,python和游标。这是我的密码 class User(): def __init__(self, config): self.con = psycopg2.connect(**config) self.cursor = self.con.cursor def getListS(self): from pprint import pprint cursor = self.cursor
class User():
def __init__(self, config):
self.con = psycopg2.connect(**config)
self.cursor = self.con.cursor
def getListS(self):
from pprint import pprint
cursor = self.cursor
cursor.execute("bla bla")
我得到了这个错误
AttributeError:“内置函数”或“方法”对象没有属性“执行”
这是因为self.con.cursor
是一个方法,应该调用它以获取cursor
对象
在getlist
方法中,执行以下操作:
cursor = self.cursor()
cursor.execute("select * ...")