python中处理pymysql取值带有Decimal和datetime.data

python通过pymysql查询出来的结果时间和金额可能都带有datetime.data 或者Decimal,还得在单独做转换处理

如何让查询的结果不带这些属性呢?

pymysql连接mysql时做如下处理:

from pymysql import converters,FIELD_TYPE

 conv = converters.conversions 

conv[FIELD_TYPE.NEWDECIMAL] = float # convert decimals to float

conv[FIELD_TYPE.DATE] = str # convert dates to strings

conv[FIELD_TYPE.TIMESTAMP] = str # convert dates to strings

conv[FIELD_TYPE.DATETIME] = str # convert dates to strings

conv[FIELD_TYPE.TIME] = str # convert dates to strings

在pymysql.connect中增加参数conv=conv,如果是线程池,就在PooledDB中增加参数conv=conv

你可能感兴趣的:(python中处理pymysql取值带有Decimal和datetime.data)