使用动态变量名承接实参


import json

json_data = json.loads(prev.getResponseDataAsString())

# Extract the currentAccountList from the JSON data
currentAccountList = json_data.get("data", {}).get("currentAccountList", [])
disbursementAccounts = json_data.get("data", {}).get("disbursementAccounts", [])

# Initialize an empty list to store account IDs where currency is KES
KES_B002_accounts = []
KES_B003_accounts = []

USD_B002_accounts = []
EUR_B002_accounts = []
CNY_B002_accounts = []
GBP_B002_accounts = []

# Iterate through each account in the current account list
for account in currentAccountList:
    if account.get("currency") == "KES":
        KES_B002_accounts.append(account.get("accountId"))
    if account.get("currency") == "USD":
        USD_B002_accounts.append(account.get("accountId"))
    if account.get("currency") == "EUR":
        EUR_B002_accounts.append(account.get("accountId"))
    if account.get("currency") == "CNY":
        CNY_B002_accounts.append(account.get("accountId"))
    if account.get("currency") == "GBP":
        GBP_B002_accounts.append(account.get("accountId"))
        
for account in disbursementAccounts:
    if account.get("currency") == "KES":
        KES_B003_accounts.append(account.get("accountId"))

 使用动态变量名承接实参

names = locals()
for index, account in enumerate(KES_B002_accounts):
    names['KES_B002_accounts_%s' % index]=account
    log.info('KES_B002_accounts_'+str(index)+':'+account)
    vars.put("KES_B002_accounts_"+str(index), account)

for index, account in enumerate(KES_B003_accounts):
    names['KES_B003_accounts_%s' % index]=account
    log.info('KES_B003_accounts_'+str(index)+':'+account)
    vars.put("KES_B003_accounts_"+str(index), account)

for index, account in enumerate(USD_B002_accounts):
    names['USD_B002_accounts_%s' % index]=account
    log.info('USD_B002_accounts_'+str(index)+':'+account)
    vars.put("USD_B002_accounts_"+str(index), account)

for index, account in enumerate(EUR_B002_accounts):
    names['EUR_B002_accounts_%s' % index]=account
    log.info('EUR_B002_accounts_'+str(index)+':'+account)
    vars.put("EUR_B002_accounts_"+str(index), account)

for index, account in enumerate(CNY_B002_accounts):
    names['CNY_B002_accounts_%s' % index]=account
    log.info('CNY_B002_accounts_'+str(index)+':'+account)
    vars.put("CNY_B002_accounts_"+str(index), account)

for index, account in enumerate(GBP_B002_accounts):
    names['GBP_B002_accounts_%s' % index]=account
    log.info('GBP_B002_accounts_'+str(index)+':'+account)
    vars.put("GBP_B002_accounts_"+str(index), account)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值