首页 > 解决方案 > Python-MySQL:如何在 Python 中的 2 个不同函数上共享或重用单个变量?

问题描述

我有 2 个不同的函数,它们分别进行查询并将数据插入到 2 个不同的 MySQL 表中。如何在第二个函数中重用变量(转换)?

def getRows():
    convert = str(rows)

def getDetails():
    productId = convert

标签: pythonmysql

解决方案


这里:

#function call

converty = getRows()
getDetails(converty)



def getRows():
    convert = str(rows)
    return convert

def getDetails(convert):
    data = aliexpress.get_product_details(['productUrl', 'discount', 'evaluateScore',
                                      'volume', 'packageType', 'lotNum', 'validTime', 'storeName', 'storeUrl','allImageUrls'], convert)
    productId = convert

推荐阅读