正在迭代的旧主题...在我的情况下,我尝试标记一个简单的字符串。我有这样的东西:
{“ clineTtype”:“门户”,“用户名”:“ TOKEN1”,“密码”:“ TOKEN2”}
。现在,我得到的是TOKEN值TOKEN1: username1,username2 | TOKEN2: password1,password2
的乘积。
因为我需要一个字典返回值,所以我为每个值“列表”构建一个字典键+值(
{“ clineTtype”:“门户”,“用户名”:“ TOKEN1”,“密码”:“ TOKEN2”}
)。
所以输出必须是这样的:
{key1:“ clineTtype”:“门户”,“用户名”:“用户名1”, “ Password”:“ password1”,key2:“ clineTtype”:“ Portal”, “ username”:“ unsername2”,“ Password”:“ password2”}
我使用singleValue做到了:
if sclTokenProcessingTestStepsValue == "singleValue":
if "testStep."+sclTestStep+".url.tokenizedBody.numTokens" in dictTestStepKeysAndValues:
sclNumTokensTestStepsValueStr = dictTestStepKeysAndValues.get("testStep."+sclTestStep+".url.tokenizedBody.numTokens")
sclNumTokensTestStepsValue = int(sclNumTokensTestStepsValueStr)
while sclNumTokensTestStepsValue > 0:
sclTokenKey = "TOKEN"
sclTokenKey += str(sclNumTokensTestStepsValue)
if "testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.singleValue."+sclTokenKey in dictTestStepKeysAndValues:
sclNumTokenValue = dictTestStepKeysAndValues.get("testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.singleValue."+sclTokenKey)
sclToken = sclTokenizedBodyTestStepsValue.replace(sclTokenKey,sclNumTokenValue)
sclTokenizedBodyTestStepsValue = sclToken
sclNumTokensTestStepsValue -= 1
sclBodyBuilderReturn = sclToken
logging.info('tokenizedBody: %s' % sclBodyBuilderReturn)
return sclBodyBuilderReturn
现在我尝试迭代:
elif sclTokenProcessingTestStepsValue == "iterating":
if "testStep."+sclTestStep+".url.tokenizedBody.numTokens" in dictTestStepKeysAndValues:
sclNumTokensTestStepsValueStr = dictTestStepKeysAndValues.get("testStep."+sclTestStep+".url.tokenizedBody.numTokens")
sclNumTokensTestStepsValue = int(sclNumTokensTestStepsValueStr)
if "testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.iterating.TOKEN1" in dictTestStepKeysAndValues:
sclTokenizedBodyNumValues = dictTestStepKeysAndValues.get("testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.iterating.TOKEN1")
lstTokenizedBodyNumValues = []
lstTokenizedBodyNumValues = sclTokenizedBodyNumValues.split(",")
LenTokenizedBodyNumValues1 = len(lstTokenizedBodyNumValues)
LenTokenizedBodyNumValues2 = len(lstTokenizedBodyNumValues)
dictTest = {}
while LenTokenizedBodyNumValues1 > 0:
integer = []
integer = sclTestStep +"-"+str(LenTokenizedBodyNumValues1)
dictTest[integer] = sclTokenizedBodyTestStepsValue
LenTokenizedBodyNumValues1 -= 1
lstTokenValue = []
while sclNumTokensTestStepsValue > 0:
sclTokenKey = "TOKEN"
sclTokenKey += str(sclNumTokensTestStepsValue)
if "testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.iterating."+sclTokenKey in dictTestStepKeysAndValues:
sclNumTokenValue = dictTestStepKeysAndValues.get("testStep."+sclTestStep+".url.tokenizedBody.tokenProcessing.iterating."+sclTokenKey)
sclNumTokenValue = sclNumTokenValue
lstTokenValue.append(sclNumTokenValue)
sclNumTokensTestStepsValue -= 1
lstAllValues = []
for steps in lstTokenValue:
nnewList = []
nnewList = steps.split(",")
for step in nnewList:
lstAllValues.append(step)
i = 0
dictEnd = {}
LenTokenizedBodyNumValues1 += 1
for i in range(LenTokenizedBodyNumValues2):
sclTest=(list(dictTest.values())[i])
test = sclTest.replace("TOKEN"+str(LenTokenizedBodyNumValues1),lstAllValues[i])
print(test)