0

I have question, which couldn't found clear answers. I am using Python and importing database from MS Access.I search for some data in database and display it on my GUI, if the data is not present, it should skip or it should print None as shows in below picture. Now i have a problem that, some how able to print in GUI, but getting unicode bracket or 'u' character at beginning. How can i remove it. GUI

My code is as below: Using some empty array to hold the database data and code is my data

DTC_Description = []

connection = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;SafeTransactions=0;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\PYTHON27;DBQ=C:\PYTHON27\iso14229dtcs.mdb;')
cursor1 = connection.cursor()
cursor1.execute("SELECT Field2 FROM DTC_CODES Where Field1 = '{}'".format(code))

# Here  it will print
row = cursor1.fetchone()
if row: 
   r1 = row[0]
   print r1
DTC_Description.append(row)

1 Answers1

0

If you know the encoding you are using in the database, you could do something like the following.

# prior to your print r1 and asuming utf-8 encoding
encoded_r1 = r1.encode('utf-8')
print encoded_r1

Also, you could check the answers in this question.

Suppress the u'prefix indicating unicode' in python strings

Community
  • 1
  • 1
valeas
  • 364
  • 1
  • 7
  • 18