gpt4 book ai didi

python - 如何在机器人框架中将列表连接到字符串

转载 作者:太空宇宙 更新时间:2023-11-03 21:03:13 24 4
gpt4 key购买 nike

我正在机器人框架中创建某个字符串的 md5 哈希值,我想拆分此哈希值并仅保留前 32 个字符。

我正在尝试使用列表,然后剪切列表,但我无法将列表连接回字符串。这是我的代码:

${test1}=    Md 5    ${pwd_arg}
${test3}= Hexdigest
${test4}= Convert To List ${test3}
${test5}= Convert To String ${test4}[0:32]
${test6}= Catenate SEPARATOR= ${test4}

这里是日志,基本上我可以剪切列表,但无法将列表上的所有元素连接回字符串

INFO : ${test3} = 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8
INFO : ${test4} = ['0', 'e', '5', '7', '5', '1', 'c', '0', '2', '6', 'e', '5', '4', '3', 'b', '2', 'e', '8', 'a', 'b', '2', 'e', 'b', '0', '6', '0', '9', '9', 'd', 'a', 'a', '1', 'd', '1', 'e', '5', 'd', 'f', '4', '7',...
INFO : ${test5} = ['0', 'e', '5', '7', '5', '1', 'c', '0', '2', '6', 'e', '5', '4', '3', 'b', '2', 'e', '8', 'a', 'b', '2', 'e', 'b', '0', '6', '0', '9', '9', 'd', 'a', 'a', '1']
INFO : ${test6} = ['0', 'e', '5', '7', '5', '1', 'c', '0', '2', '6', 'e', '5', '4', '3', 'b', '2', 'e', '8', 'a', 'b', '2', 'e', 'b', '0', '6', '0', '9', '9', 'd', 'a', 'a', '1']
FAIL : b1404d6cc07abe3805e5960771c0ba72 != 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8
Ending test

感谢您的帮助。

最佳答案

首先,有一种更简单的方法可以在机器人中对列表进行切片。而且,转换为字符串 无法按照您在代码中预期的方式工作。

下面是实现您想要做的事情的代码:

${test4}=                 Convert To List      ${test3}
${test5}= Get Slice From List ${test4} 0 32
${convertListToString}= Evaluate "".join(${test5})
${test6}= Catenate SEPARATOR= ${convertListToString} ${otherStringToCatenate}

Evaluate "".join(${test5}) 会将列表转换为字符串,然后您可以使用 Catenate 关键字连接到其他字符串。

关于python - 如何在机器人框架中将列表连接到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55589637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com