至少应该包含使用 Robotframework
Should contain atleast using Robotframework
在 @{test} XTEAMK01, KKTEAM01, XTEAMO01, KKTEAM02, XJSTEAMD00, KKTEAM03
中创建了一个列表,然后我想获得以下以“KK”开头的值
KKTEAM01, KKTEAM02,KKTEAM03
您可能正在寻找 startwith. Here it is used with a list comprehension。
In [1]: l = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
In [2]: [x for x in l if x.startswith("KK")]
Out[2]: ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
您可以使用list compreenhension and startswith
kk_list = [item for item in full_list if item.startswith("KK")]
您可以使用列表理解:
inp = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
output = [x for x in inp if x[:2] == 'KK']
print(output) # ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
或者,使用正则表达式以获得更灵活的选项:
inp = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
output = [x for x in inp if re.search(r'^KK', x)]
print(output) # ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
使用@WindCheck,您可以格式化代码以在机器人中工作。此代码将产生您想要的结果。
***Variables***
@{test} XTEAMK01 KKTEAM01 XTEAMO01 KKTEAM02 XJSTEAMD00 KKTEAM03
*** Test Cases ***
Example
${x}= Evaluate [item for item in ${test} if item.startswith("KK")]
Log ${x}
或者您也可以使用其他答案。
您可以使用机器人的 inline python evaluation 进行列表理解:
log matches: ${{[x for x in $test if x.startswith('KK')]}}
或者,您可以使用 Evaluate 以更易读的格式执行相同的列表理解:
@{matches}= Evaluate [x for x in $test if x.startswith('KK')]
在 @{test} XTEAMK01, KKTEAM01, XTEAMO01, KKTEAM02, XJSTEAMD00, KKTEAM03
中创建了一个列表,然后我想获得以下以“KK”开头的值
KKTEAM01, KKTEAM02,KKTEAM03
您可能正在寻找 startwith. Here it is used with a list comprehension。
In [1]: l = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
In [2]: [x for x in l if x.startswith("KK")]
Out[2]: ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
您可以使用list compreenhension and startswith
kk_list = [item for item in full_list if item.startswith("KK")]
您可以使用列表理解:
inp = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
output = [x for x in inp if x[:2] == 'KK']
print(output) # ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
或者,使用正则表达式以获得更灵活的选项:
inp = ["XTEAMK01", "KKTEAM01", "XTEAMO01", "KKTEAM02", "XJSTEAMD00", "KKTEAM03"]
output = [x for x in inp if re.search(r'^KK', x)]
print(output) # ['KKTEAM01', 'KKTEAM02', 'KKTEAM03']
使用@WindCheck,您可以格式化代码以在机器人中工作。此代码将产生您想要的结果。
***Variables***
@{test} XTEAMK01 KKTEAM01 XTEAMO01 KKTEAM02 XJSTEAMD00 KKTEAM03
*** Test Cases ***
Example
${x}= Evaluate [item for item in ${test} if item.startswith("KK")]
Log ${x}
或者您也可以使用其他答案。
您可以使用机器人的 inline python evaluation 进行列表理解:
log matches: ${{[x for x in $test if x.startswith('KK')]}}
或者,您可以使用 Evaluate 以更易读的格式执行相同的列表理解:
@{matches}= Evaluate [x for x in $test if x.startswith('KK')]