使用MySQLdb执行sql语句报错:
cursor.execute("insertinto hq_rank_xueqiu(symbol,name,current) values(%s,%s,%.1f)",(‘12‘,‘123‘,12.2))
MySQLdbTypeError: float argument required, not str 插入的current字段明明是float类型,却报错提示类型错误,查找官网原文
Notice that there is a mix of types (strings, ints, floats) though we still only use %s
也就是说mysqldb提供的字符串格式化并不是python的字符串格式化,所有的变量类型插入 的时候都必须用%s代替,于是将%.1f替换成%s就可以了
>>>cursor.execute("insertinto hq_rank_xueqiu(symbol,name,current) values(%s,%s,%s)",(‘12‘,‘123‘,12.3))
时间: 2024-10-07 19:33:18