我想序列化查询的结果。这是我的例子:
import pypyodbc
import pickle
connection_string ='Driver={SQL Server Native Client 11.0};Server=localhost;' \
'Database=someDB;Uid=someLogin;Pwd=somePassword;'
connection = pypyodbc.connect(connection_string)
sql_query = "SELECT * FROM SomeTable"
cur = connection.cursor()
cur.execute(sql_query)
query_list = list(cur)
with open(r'D:\query_result', 'wb') as f:
pickle.dump(query_list, f)
cur.close()
connection.close()
它会产生以下错误:
_pickle.PicklingError: Can't pickle <class 'pypyodbc.TupleRow.<locals>.Row'>:
attribute lookup Row on pypyodbc failed
我猜 pickle 不完全支持 pypyodbc 对象。什么是解决方法?