程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

python使用pymysql插入数字时总提示must be real number, not str

发布于2019-09-06 12:10     阅读(2587)     评论(0)     点赞(18)     收藏(4)


代码如下:

sql = 'insert into equipment (order_id, equip_id, name, model, specification, purchase_date, unit_price, owner, owner_department, address, status) values (%s, %s, %s, %s, %s, %s, %f, %s, %s, %s, %s)'
val = ('', '19960100', '生化培养箱', 'LRH--250A', '*', datetime.datetime(1997, 7, 1, 0, 0), 6444.0, 'xx', '创新实验室', '医药楼2-112', '在用')
try:
    conn = pymysql.connect(host='127.0.0.1',
                           port=3306,
                           user='root',
                           password='xxxx',
                           db='assets',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)
    with conn.cursor() as cursor:
        cursor.execute(sql, val)
        conn.commit()
except Exception as e:
    print(e)
finally:
    conn.close()

unit_price数据库中类型的是float,但是每次插入的时候总是提示must be real number, not str,这个是为啥呢?是不是pymysql会自动转换数字成字符串?



所属网站分类: 技术文章 > 博客

作者:python是我的菜

链接:https://www.pythonheidong.com/blog/article/98407/460209a7190423042aee/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

18 0
收藏该文
已收藏

评论内容:(最多支持255个字符)