这个错误让我很方啊。首先我的字段类型是用utf8mb4_unicode_ci编码的,防止emoji之类的显示不出来嘛,虽然说不会有emoji出现吧。

name = ['军事', '科幻', '美食', '散文', '童话', '政治', '哲学']
for na in name:
    a = random.randint(2, 5)
    #print type(a)
    con.execute("update b set maxstore=(%d) where bk=%s"%(a, na))
    con.execute("update b set rest=(%d) where bk=%s"%(a, na))
'''
a = random.randint(2, 5)
con.execute("update b set maxstore=(%d) where bk='医药'"%(a))
con.execute("update b set rest=(%d) where bk='医药'"%(a))
'''

没加注释的是报错的,加了注释的是正确的,就是为了省时才写的脚本,结果呵呵了,这两种方式有啥区别吗?为啥上边的就不对呢?有待研究。。。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

11.16 问题解决:

bk = u'美食'
con.execute("use librarysystem")   
con.execute("select * from b where bk='"+bk+"'")
ans = con.fetchall()
if ans:
    print(ans)
    print(ans[0][0])

这样就可以了。

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2021-11-13
  • 2022-12-23
  • 2021-09-29
  • 2021-08-08
  • 2021-07-30
猜你喜欢
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-05-25
相关资源
相似解决方案