[python3] torndb中的itertools.zip

2017-12-06  本文已影响0人  bnl

       今天,使用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()

上一篇 下一篇

猜你喜欢

热点阅读