当前位置: 首页 > 面试题库 >

TypeError:只能将元组(不是'nt')连接到元组

袁高明
2023-03-14
问题内容

我正在尝试从db返回值并收到此错误。我在这里尝试了先前回答的问题,但是没有运气。有人可以帮助我吗?

@frappe.whitelist()
def generate_barcode():

    last_barcode = frappe.db.sql("""\
        select MAX(barcode) from `tabItem` """)

    if last_barcode:
        last_barcode = last_barcode + 1

    else:
        x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
        random.shuffle(x)
        last_barcode = x[0]



    return {'last_barcode':last_barcode}

添加回溯:

Traceback (innermost last):
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/app.py", line 49, in   application
response = frappe.handler.handle()
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 66, in handle
execute_cmd(cmd)
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/__init__.py", line 531, in   call
return fn(*args, **newargs)
File "/home/adminuser/frappe-bench-hitech/apps/erpnext/erpnext/stock/doctype/item/item.py", line 405, in generate_barcode
last_barcode = last_barcode + 1
TypeError: can only concatenate tuple (not "int") to tuple

问题答案:

我以某种方式得到了答案。感谢大家的帮助。

@frappe.whitelist()
def generate_barcode():

last_barcode_auto = frappe.db.sql("""\
    select MAX(barcode) from `tabItem` """)

if last_barcode_auto[0][0] :
    last_barcode = last_barcode_auto[0][0]
    final_barcode= last_barcode+1

else:
    final_barcode=random.randrange(100001, 100000000000, 2)



return {'final_barcode':final_barcode}


 类似资料:
  • 问题内容: 我正在尝试制作一个程序,将某个质量和体积的密度与化合物的密度列表进行比较,然后返回我正在分析的化合物的类型。 这是返回错误的代码部分: 错误信息: 问题答案: 您对此有一些选择 使用和相同 或者,您也可以将它们转换为当您以这种方式执行时,您可以保留值,就好像您要进行更多的计算一样,而不必一遍又一遍地来回转换它们。

  • 如何修复TypeError:只能将数组(不是“字节”)连接到数组 最近我在学Python,从网上获取了一个作品,程序结果应该是从网上获取scratch文件。第一次执行时成功了,但是第二次就不行 部分代码: 全部代码: 第二次的时候一直提示“TypeError:can only append array (not "bytes") to array” 怎么才能把这个代码搞好?

  • 我正在尝试使工作,当我运行命令时,我得到以下错误: “@babel/core”:“^7.12.0”, “巴别塔”:“^6.23.0”, “BABEL-CLI”:“^6.26.0”, “Babel-Eslint”:“^8.2.3”, “Babel-Loader”:“^7.1.4”, “babel-plugin-module-alias”:“^1.6.0”, “babel-plugin-syntax-

  • 问题内容: 我有点困惑。我在任何地方都找不到答案;( 我有一个String数组: 然后我通过以下方式将其转换为字符串: 我期望得到字符串,但是我却得到了字符串。 我该如何在Java中做到这一点?我正在使用Eclipse IDE 问题答案: 使用 StringBuilder 而不是StringBuffer,因为它比StringBuffer快 。 样例代码 这是使用字符串连接的更好解决方案的原因:当连

  • 我要做的事 我正在使用一个名为的类和一个名为(生成一个容易记住的密码)和的函数来生成一个密码生成器,这两个函数将生成一个复杂的密码。 我的代码: 我的问题 当我运行这个程序时,我得到一个错误: 完全错误: 回溯(最近一次调用):文件“C:\users\sbenf\oneDrive\python projects\large projects\adventure_colussus_game\pass

  • 我是使用火花和蟒蛇的新手 我有以下元组 我要做的是,从每个元素中减去,例如(4.32,32.32,23.3),每个帐户对应的平均值,到4.32-3.23,到32.32-32.32。。。 我的想法是做到以下几点。 但是我不知道如何才能正确地输入索引。 我的输入文件具有以下结构。 然后我计算每行的平均值,因此例如对于所有名为Serge的Keys,我有以下数据元组。 现在我想要的是减去每个元素的平均值.