在 Robot Framework 中修改列表列表 [英] Modifying lists of lists in Robot Framework

查看:32
本文介绍了在 Robot Framework 中修改列表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Robot Framework 中使用的嵌套列表.我想在机器人框架级别更改子列表中的一项.

I have a nested list that I am using in Robot Framework. I would like to change one item in a sublist at the Robot Framework level.

我的列表如下所示:

[鲍勃,玛丽,[六月、七月、八月]]

[ bob, mary, [june, july, august]]

我想把七月"改成别的,比如九月"

I want to change "july" to something else, say "september"

Robot Framework 可以让我更改 'bob' 或 'mary',但是如果我尝试插入一个列表,它会被转换为字符串.

Robot Framework will let me change 'bob' or 'mary', but if I try to insert a list, it is converted into strings.

(哦,我试过用Insert Into List 关键字插入一个新的子列表,还有其他的 List 关键字,都没有成功.)

(Oh, I have tried to use the "Insert Into List keyword to insert a new sub list, and other List keywords, no luck with any.)

推荐答案

我猜测由于缺乏响应,没有一个简洁干净的解决方案.这是我所做的:

I am guessing from the lack of response that there isn't a neat clean solution to this. Here is what I have done:

我因此创建了一个实用程序:

I created a utility thusly:

class Pybot_Utilities:
    def sublistReplace(self, processList, item, SublistIndex, ItemIndex):
        '''
        Replaces an item in a sublist
        Takes a list, an object, an index to the sublist, and an index to a location in the sublist inserts the object into a sublist of the list at the location specified. 
        So if the list STUFF is (X, Y, (A,B,C)) and you want to change B to FOO give these parameters: [STUFF, FOO, 2, 1]
        '''

        SublistIndex=int(SublistIndex)
        ItemIndex=int(ItemIndex)
        processList[SublistIndex][ItemIndex] = str(item)
        return processList

然后我将此条目放入我的机器人框架测试套件文件中:

I then put this entry in my robot framework test suite file:

|    | ${ListWithSublist} = | sublistReplace    | ${ListWithSublist]}  | NewItem | 1 | 1 |

(当然是导入我的实用程序库)

(Importing my utility library, of course)

执行此操作后,列表索引 1 处的子列表中的第二项(索引 1)将是NewItem"

After this runs, the second item (index 1) in the sublist at index 1 of the list will be "NewItem"

也许不是最优雅或最灵活的,但它现在可以胜任

Perhaps not the most elegant or flexible, but it will do the job for now

这篇关于在 Robot Framework 中修改列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆