开发者社区> 问答> 正文

在python和mysql中,int()不能使用显式基来转换非字符串

c.execute("select * from Cases")
k = c.fetchall()
for l in k:
    c.execute("SELECT * FROM Cases where CaseName = '%s'" % str(self.CASE_NAME.get()))
    l = c.fetchone()
    # these are total quantities
    bar = l[2] * 24
    foo = l[6]
    if bar + foo == 0:
        print('Out of Stock!!')
    if int(self.CASE_QUANTITY.get()) > bar + foo:
        print('Stock less than value given \n Provide smaller quantity.')
    if foo == 0:
        print('zero')
        total = bar - int(self.CASE_QUANTITY.get())
        print(total)
        # dividing and splitting
        div = divmod(total, 24)
        print(div)
        print(div[0])
        print(div[1])
        case = div[0]
        piece = div[1]
        c.execute("update Cases set CaseQuantity =%s and Piece= %s WHERE CaseName = %s",
                  (int(case, int(piece)), self.CASE_NAME.get()))
        print('success')
    else:
        total2 = (foo + bar) - int(self.CASE_QUANTITY.get())
        # diving and splitting
        div2 = divmod(total2, 24)
        print(div2)
        print(div2[0])
        print(div2[1])
        case1 = div2[0]
        piece1 =div2[1]
        c.execute("update Cases set CaseQua"
                  "ntity =%s and Piece=%s WHERE CaseName = %s",
                  (case1, int(piece1), self.CASE_NAME.get()))
        print('success')

1箱等于24块。因此,当用户请求分块产品时,代码将用24来乘以将其转换为分块,然后减去请求的分块。然后模数被用来将棋子转换成格。例如,假设有20种情况。下面将进行计算。20 * 24。如果用户要求5件。{5}(20 * 24)。转换为案例divmode((20*24)-5)。索引0上的整数被更新为案例数量。第二个索引上的整数更新到数据库表中的块,例如[19,7]。下面的错误出现每次我运行的代码:在选择

(int(case, int(piece)), self.CASE_NAME.get()))

TypeError: int() can't convert non-string with explicit base

问题来源StackOverflow 地址:/questions/59466989/typeerror-int-cant-convert-non-string-with-explicit-base-in-python-and-mysql

展开
收起
kun坤 2019-12-25 09:36:09 591 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像