I am learning Python and have written some code to retrieve data from a SQL Server table. The code is as follows:
import pyodbc
connection = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
"Server=xxx"
"Database=xxx"
"uid=xxx"
"pwd=xxx"
)
cursor = connection.cursor()
cursor.execute('SELECT * FROM Dealers')
for row in cursor:
print(list(row))
This code works fine but the output, for some data types isn't what I expected. For example, I have a line of output that looks like this:
Decimal('0.000'), Decimal('83.360'), True, True, Decimal('0.000'), datetime.date(2017, 5, 31), True, 1, True, True, datetime.datetime(2017, 5, 31, 18, 28, 57, 686666)
Instead of something like Decimal('83.360'), how do I simply get 83.360? Same for the date/time values?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…