Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:只能将元组(而不是“int”连接到元组_Python_Sql_Tuples_Mariadb_Frappe - Fatal编程技术网

Python TypeError:只能将元组(而不是“int”连接到元组

Python TypeError:只能将元组(而不是“int”连接到元组,python,sql,tuples,mariadb,frappe,Python,Sql,Tuples,Mariadb,Frappe,我正在尝试从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:

我正在尝试从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”是什么,您没有发布完整的回溯,因此我们只能尝试猜测,但很明显,
frappe.db.sql(“从
tabItem
中选择最大(条形码)”)
返回一个元组(这是我希望从sql数据库中选择的元组),因此您需要类似以下内容:

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

last_barcode = row[0]
if last_barcode:
    last_barcode = last_barcode + 1

作为旁注:如果您想要一个介于0和9(包括)之间的随机整数,它的拼写是
random。randint(0,9)

错误消息是说
last\u barcode
是一个元组。使用
last\u barcode[0]
检索第一个值(在本例中,该值是唯一的值,因为您选择了一列)


我不知怎么得到了答案。谢谢大家的帮助

@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}

if
select
之间的
最后一个条形码包含什么?它包含一个数字字符串。或者
随机。randrange(10)
我尝试了这个方法,但仍然得到相同的错误,而且Frappe是一个框架。
@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}