用于处理结果集的模块 [英] module for working with the result set
问题描述
新手问题:
PyPgSQL(postgres驱动程序)返回一个列表(不是元组O''Rielly状态
DBAPI返回一个元组)并且大多数书籍描述了在使用结果集时如何使用
元组和字典。有没有人知道
的论文或教程解释了几种处理结果的方法
套。或者,如果有人知道一个可以提供帮助的模块(我可以学习) -
这对我们有帮助吗?
TIA
John
john fabiani写道:
新手问题:
PyPgSQL(postgres驱动程序)返回一个列表(不是元组O''Rielly状态说明DBAPI返回一个元组),大多数书籍描述了如何使用
元组和词典。结果集。有没有人知道一篇论文或教程,它解释了处理结果集的几种方法。或者,如果有人知道一个有用的模块(我可以学习) -
那会有帮助吗?
究竟是什么问题?列表的行为与阅读
加入元组的行为相同。所以无论你想用一个元组做什么,都要做。
-
问候,
Diez B. Roggisch
Diez B. Roggisch写道:john fabiani写道:
新手问题:
PyPgSQL(postgres驱动程序)返回一个列表(不是元组O''Rielly状态说明DBAPI返回一个元组)并且大部分书籍描述了如何使用
使用结果集时的元组和词典。有没有人知道一篇论文或教程,它解释了处理结果集的几种方法。或者,如果有人知道一个有用的模块(我可以学习) -
那会有帮助吗?
究竟是什么问题?列表在读取元组时具有相同的行为。无论你想用一个元组做什么,都要做。
这就是我的想法,但每当我尝试使用任何一个例子时
O''Reilly书中的
我收到错误。我对这些东西很陌生我不能告诉我这是不是我或者我不使用元组的事实。如下所示:
mydata = cursor.fetchmany(10)
$ m $ b for mydata [0]中的字段:
打印mydata [0] [field]
Traceback(最近一次调用最后一次):
文件" C:\Python23 \Lib \ site- packages\sm\scriptutils.py",第49行,在运行中
exec codeObject in mainDict
文件"< source>",第10行,in ?
文件C:\Python23 \Lib\site-packages \pyPgSQL \PgSQL.py,第2063行,
__getitem __
key = self._xlatkey [key.lower()]
KeyError:''5992''
运行脚本< source>时出现异常
但是;(
打印mydata [0] [0],mydata [0] [1]
以上作品完美 - 打印我想要的东西。
所以我很困惑。另外,使用像dtuple模块这样的东西根本不会起作用。
。 />
谢谢
John
john fabiani写道:
mydata = cursor.fetchmany(10)
对于mydata [0]中的字段:
print mydata [0] [field]
我想你想要:
mydata = cursor.fetchmany(10)
在mydata中记录:
print" --- record ---"
for record in record:
打印字段
Hi,
newbie question:
PyPgSQL (postgres driver) returns a list (not a tuple O''Rielly states
DBAPI returns a tuple) and most of the books describe how to work with
tuples and dictionaries when working with a result set. Does anyone know
of a paper or tutorial that explains a few ways to deal with result
sets. Or if anyone knows of a module that will help (that I can study) -
that would be just as helpful?
TIA
John解决方案john fabiani wrote:
Hi,
newbie question:
PyPgSQL (postgres driver) returns a list (not a tuple O''Rielly states
DBAPI returns a tuple) and most of the books describe how to work with
tuples and dictionaries when working with a result set. Does anyone know
of a paper or tutorial that explains a few ways to deal with result
sets. Or if anyone knows of a module that will help (that I can study) -
that would be just as helpful?
What exactly is your problem? Lists behave equally with respect to read
accees to tuples. So whatever you want to do with a tuple, do it.
--
Regards,
Diez B. Roggisch
Diez B. Roggisch wrote:john fabiani wrote:Hi,
newbie question:
PyPgSQL (postgres driver) returns a list (not a tuple O''Rielly states
DBAPI returns a tuple) and most of the books describe how to work with
tuples and dictionaries when working with a result set. Does anyone know
of a paper or tutorial that explains a few ways to deal with result
sets. Or if anyone knows of a module that will help (that I can study) -
that would be just as helpful?
What exactly is your problem? Lists behave equally with respect to read
accees to tuples. So whatever you want to do with a tuple, do it.
That''s what I thought but everytime I attempt to use any of the examples
in the O''Reilly books I get errors. I''m so new to this stuff I can''t
tell if it''s me or the fact I not using tuples. Things like the following:
mydata=cursor.fetchmany(10)
for field in mydata[0]:
print mydata[0][field]
Traceback (most recent call last):
File "C:\Python23\Lib\site-packages\sm\scriptutils.py", line 49, in run
exec codeObject in mainDict
File "<source>", line 10, in ?
File "C:\Python23\Lib\site-packages\pyPgSQL\PgSQL.py", line 2063, in
__getitem__
key = self._xlatkey[key.lower()]
KeyError: ''5992 ''
Exception raised while running script <source>
But ;(
print mydata[0][0], mydata[0][1]
the above works perfectly - prints what I want.
So I''m confused. Also, using things like the dtuple module does not
work at all.
thanks
John
john fabiani writes:
mydata=cursor.fetchmany(10)
for field in mydata[0]:
print mydata[0][field]
I think you want:
mydata=cursor.fetchmany(10)
for record in mydata:
print "--- record ---"
for field in record:
print field
这篇关于用于处理结果集的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!