2006年07月07日 星期五 23:31
是我不会用还是怎么的,只能通过数字下标来取得字段值 如果真的是这样怎么从来没听人说这个事呢?是不是有什么办法就我不知道? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060707/16cbed32/attachment.htm
2006年07月08日 星期六 01:09
用下标来获得相应的值很正常。 当然,你最好写成 SELECT A,B,C FROM T 而尽量少写 SELECT * FROM T。 这样就一点也不混乱了是不是? > 是我不会用还是怎么的,只能通过数字下标来取得字段值 > 如果真的是这样怎么从来没听人说这个事呢?是不是有什么办法就我不知道? > ------------------------------------------------------------------------ > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年07月08日 星期六 10:30
On 7/8/06, Ni ZhengGang <ni at twinisa.com> wrote: > 用下标来获得相应的值很正常。 > 当然,你最好写成 SELECT A,B,C FROM T 而尽量少写 SELECT * FROM T。 > 这样就一点也不混乱了是不是? > > > 是我不会用还是怎么的,只能通过数字下标来取得字段值 > > 如果真的是这样怎么从来没听人说这个事呢?是不是有什么办法就我不知道? 如果使用db-api的话,是通过下标。如果使用ORM的包,如SQLAlchemy是可以通过字段名来取的。 -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年07月08日 星期六 21:27
cursor object不是有description属性吗?result set的结构都在这里面。 没有必要在没条记录里包括这些信息,那样太冗余了,这和jdbc的设计也是一致的。 On 7/7/06, wang dy <dongyang.wang at gmail.com> wrote: > > 是我不会用还是怎么的,只能通过数字下标来取得字段值 > 如果真的是这样怎么从来没听人说这个事呢?是不是有什么办法就我不知道? > > _______________________________________________ > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060708/aebd9f3b/attachment.htm
2006年07月08日 星期六 22:26
谢谢各位,现在这样整了,
def field_dict(curs):
rf = {}
i=0
for fld in curs.description:
rf[fld[0]] = i
i=i+1
return rf
curs.execute(sql)
fields = field_dict(curs)
row = curs.fetchone()
print row[fields['FIELD_NAME']]
在06-7-8,swordsp <sparas2006 at gmail.com> 写道:
>
> cursor object不是有description属性吗?result set的结构都在这里面。
> 没有必要在没条记录里包括这些信息,那样太冗余了,这和jdbc的设计也是一致的。
>
> On 7/7/06, wang dy < dongyang.wang at gmail.com> wrote:
> >
> > 是我不会用还是怎么的,只能通过数字下标来取得字段值
> > 如果真的是这样怎么从来没听人说这个事呢?是不是有什么办法就我不知道?
> >
> > _______________________________________________
> >
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060708/bd505380/attachment.htm
Zeuux © 2025
京ICP备05028076号