如何将sql结果中的给定列表匹配到字典中? 这是我的密码:
import cx_Oracle
con = cx_Oracle.connect('fmstech','fmstech','fmsdev')
cur = con.cursor()
cur.execute("select * from num_prefix where network = 'GLOBE'")
globe = ['639988800000', '639066256904', '0150422 153023']
results = {}
for lines in cur:
results[lines[0]]=lines[1]
globe1 = globe[1][2:5]
if globe1 in results:
print '906 is exist'
else:
print '906 is not exist'
cur.close()
con.close()
但是我得到了结果:906 is not exist
解决办法就是这样。使用
int()
示例1:不带out int()
o/p公司
示例2:with int()
o/p公司
原因:
在dict中,这里的键是数字,而在代码中,as globel是字符串。所以把它转换成数字然后比较
相关问题 更多 >
编程相关推荐