0
嘗試設置一個類,該類將數據庫光標傳遞回來,以便在各種函數中使用。下面的代碼不起作用Python:將一個光標從一個類傳回給一個dbi實例
class create_db(object):
def __init__(self):
import psycopg2 as pq
self.cn = pq.connect('dbname=mydb user=me')
self.cr = self.cn.cursor()
我想什麼,能夠做的就是
cur = create_db()
cur.execute('SELECT * FROM table1;')
我怎樣才能改變我的代碼來解決這個問題。