Robot Framework:读取文本文件并使用键和数组值创建字典

时间:2017-08-03 08:27:18

标签: dictionary robotframework

我的文字示例.txt文件testing.txt看起来像这样

city germany
language english
city france
Capital paris
Capital Delhi

现在我想要像这样创建一个字典

{city: germany, fance; language: english ; Capital: paris,Delhi}

我的示例代码是:

${my_dict}=    Create Dictionary
#@{keys}=    Get Dictionary Keys    ${key}
${data}    OperatingSystem.Get File    

C:\\Users\\cpt2deh\\Desktop\\cmptl\\Sprint19\\Testing\\pythonexercise-lib\\test\\Output2\\Testing.txt
    @{lines}    Split To Lines    ${data}
    Remove Values From List    ${lines}    ${EMPTY}
    :FOR    ${line}    IN    @{lines}
    \    ${key}    ${value}    Split String    ${line}                
    #\    Log to console    ${key}    
    #\    Log to console    ${value}
    \    Run Keyword If    '${key}'!= '${empty}'    Set To Dictionary    ${my_dict}    ${key}    ${value}
    \    Run Keyword If    '${value}'!='${empty}'    Append To List    ${my_dict}    ${key}    ${value}
    \    Set To Dictionary    ${my_dict}    ${key}    ${value}
    Log to console    ${my_dict}

请帮助我,因为我没有在Array中获取值

0 个答案:

没有答案