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
reprlooks like one. You'll need to convert it to a Tuple. On their site they sayNote that slicing rows returns tuples, not Row objects!does that meanaddress_result[0][:]would be OK?1819 Harras Blvdwill actually be returned as1819 Harras Blvd[space][space][space].