Reputation: 2873
I am trying to compare the output of a MSSQL (pyodbc) query against a seemingly similar tuple of strings, and python keeps telling me that they don't match.
def test_internship_direct_app_a_submit(self):
address_result = SQLHelper.address_result("""
select top 2 blah, blah, blah
""" )
print address_result[0]
print type(address_result[0])
print address_result[0] == ('1819 Harras Blvd', '', 'Atlantic City', 'NJ', '08401')
Console Output: (u'1819 Harras Blvd', u'', u'Atlantic City', 'NJ', u'08401')
type 'pyodbc.Row'
False
Question: how can manipulate the output from the database in order for it to be easily compared to a list of strings in a tuple? Thanks in advance
Oh, and here is the code in python I use to fetch the data:
def address_result(sql, param1):
cnxn = pyodbc.connect(connect_string)
cursor = cnxn.cursor()
params = (param1)
cursor.execute(sql ,params)
rows = cursor.fetchall()
addresses= []
for row in rows:
addresses.append(row)
cursor.close()
cnxn.close()
return addresses
Upvotes: 0
Views: 2165
Reputation: 2049
The problem is that the objects being returned from the database are of type pyodbc.Row not real tuples.
Add this to the end of your test script and attain enlightenment:
print tuple(address_result[0]) == ('1819 Harras Blvd', '', 'Atlantic City', 'NJ', '08401')
Upvotes: 2