美文网首页
[python3] torndb中的itertools.zip

[python3] torndb中的itertools.zip

作者: bnl | 来源:发表于2017-12-06 21:01 被阅读0次

       今天,使用torndb的过程中发现了报了下面这个错误,

File "C:\Python36\lib\site-packages\torndb.py", line 138, in query return [Row(itertools.izip(column_names, row)) for row in cursor] File "C:\Python36\lib\site-packages\torndb.py", line 138, inreturn [Row(itertools.izip(column_names, row)) for row in cursor]

AttributeError: module 'itertools' has no attribute 'izip'

        查了下文档,发现python3中filter,map,zip本身就已经是generator了,所以itertools.izip就显得有点多余了,所以也就没有了.

只需要简单的修改代码就可以,

defquery(self, query, *parameters, **kwparameters):

"""Returns a row list for the given query and parameters."""

cursor =self._cursor()

try:

self._execute(cursor, query, parameters, kwparameters)

column_names = [d[0]fordincursor.description]

# return [Row(itertools.izip(column_names, row)) for row in cursor]

return[Row(zip(column_names, row))for row in cursor]

finally:

cursor.close()

相关文章

网友评论

      本文标题:[python3] torndb中的itertools.zip

      本文链接:https://www.haomeiwen.com/subject/yuolixtx.html