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)