首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从python列表获取不正确的结果

从python列表获取不正确的结果
EN

Stack Overflow用户
提问于 2015-03-26 04:14:55
回答 1查看 45关注 0票数 0

我正在从postgres表读取数据,我正在读取的其中一个字段具有以下数据:

代码语言:javascript
复制
'1', '1', '203316-01', 'Outdoor Bistro Infrared Heated Table'

遍历字典,我将这些值赋给一个属性sg_item_list,然后使用这个字段创建一个列表。

代码语言:javascript
复制
['1', '1', '203316-01', 'Outdoor Bistro Infrared Heated Table']

使用以下python脚本:

代码语言:javascript
复制
cnt = 0
    new_dsL = []
    for sg_item in dsL:
        sg_itemL = eval(sg_item.sg_item_list)
        print 'list printed', sg_itemL
        for i_row in sg_itemL:
            cnt += 1
            print 'printing list', cnt, i_row
            #print 'debugg i_row:',i_row[2]
            if len(i_row) >= 3 :  #and i_row[2] in boD:
                print 'debugg:',i_row[2]
                sg_item.sg_bo_ind = 'True'
        new_dsL.append(sg_item)
    dsL = new_dsL

我遍历了列表,但得到了不正确的结果,如下所示:

代码语言:javascript
复制
xxxx@xxxx /cygdrive/c/Reports/SI_Reconciliation_Reporting
 $ /cygdrive/c/Python27-64/python.exe ./bin/si_under_dev_rpt-drop-ship-orders-last-60-days.py
 list printed ['1', '1', '203316-01', 'Outdoor Bistro Infrared Heated Table']
 printing list 1 1
 printing list 2 1
 printing list 3 203316-01
 debugg: 3
 printing list 4 Outdoor Bistro Infrared Heated Table
 debugg: t
 RPT: Create the DS Last 60 Days Report. version: R1

我应该看到203316-01而不是3或t。

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2015-03-26 04:33:53

你在你的调试行中建立了索引,得到了"203316-01“和"Outdoor Bistro红外线加热表”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29265650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档