how can match given list sql result dictionary? here code:
import cx_oracle con = cx_oracle.connect('fmstech','fmstech','fmsdev') cur = con.cursor() cur.execute("select * num_prefix network = 'globe'") globe = ['639988800000', '639066256904', '0150422 153023'] results = {} lines in cur: results[lines[0]]=lines[1] globe1 = globe[1][2:5] if globe1 in results: print '906 exist' else: print '906 not exist' cur.close() con.close()
but got result:906 not exist
solution this. use int()
globe1 = int(globe[1][2:5])
example 1: with out int()
results = {817: 'globe', 906: 'globe'} globe = ['639988800000', '639066256904', '0150422 153023'] globe1 = globe[1][2:5] if globe1 in results: print '906 exist' else: print '906 not exist'
o/p
906 not exist
example 2 : int()
results = {817: 'globe', 906: 'globe'} globe = ['639988800000', '639066256904', '0150422 153023'] globe1 = int(globe[1][2:5]) if globe1 in results: print '906 exist' else: print '906 not exist'
o/p
906 exist
reason :
in dict key number here globel string in code. convert number , compare.
Comments
Post a Comment