Python 如何在robot框架中为将Csv读取为字典提供参数

Python 如何在robot框架中为将Csv读取为字典提供参数,python,csv,dictionary,automation,robotframework,Python,Csv,Dictionary,Automation,Robotframework,我使用的是运行在Python 3.7.5上的RIDE 1.7.3.1。Iam正在执行从frpm python 27到python 37的迁移过程。在Python27中,我使用关键字read csv file to associative将csv文件作为字典读取。例如,如果我的csv文件是 id,name,age,height,weight 1,Alice,20,62,120.6 2,Freddie,21,74,190.6 3,Bob,17,68,120.0 我想要如下输出 {'age': '2

我使用的是运行在Python 3.7.5上的RIDE 1.7.3.1。Iam正在执行从frpm python 27到python 37的迁移过程。在Python27中,我使用关键字read csv file to associative将csv文件作为字典读取。例如,如果我的csv文件是

id,name,age,height,weight
1,Alice,20,62,120.6
2,Freddie,21,74,190.6
3,Bob,17,68,120.0
我想要如下输出

{'age': '20', 'height': '62', 'id': '1', 'weight': '120.6', 'name': 'Alice'}     
{'age': '21', 'height': '74', 'id': '2', 'weight': '190.6', 'name': 'Freddie'}     
{'age': '17', 'height': '68', 'id': '3', 'weight': '120.0', 'name': 'Bob'}     
在python 37中,仅支持csvlib 1.0.0。 它包含以下关键字

Read CSV As Single List
Read CSV As List
Read CSV As Dictionary
我正在使用以下库

pip freeze

Appium-Python-Client==0.48
bcrypt==3.1.7
beautifulsoup4==4.8.1
certifi==2019.9.11
cffi==1.13.2
chardet==3.0.4
coverage==4.5.4
cryptography==2.8
decorator==4.4.1
docutils==0.15.2
idna==2.8
importlib-metadata==0.23
jsonpatch==1.24
jsonpath-rw==1.4.0
jsonpath-rw-ext==1.2.2
jsonpointer==2.0
kitchen==1.2.6
more-itertools==7.2.0
numpy==1.17.4
oauthlib==3.1.0
paramiko==2.6.0
pbr==5.4.3
Pillow==6.2.1
pluggy==0.13.0
ply==3.11
py==1.8.0
pycparser==2.19
Pygments==2.4.2
PyNaCl==1.3.0
PyPubSub==3.3.0
pywin32==227
requests==2.22.0
requests-oauthlib==1.3.0
robotframework==3.1.2
robotframework-appiumlibrary==1.5.0.4
robotframework-csvlib==1.0.0
robotframework-extendedrequestslibrary==0.5.5
robotframework-ftplibrary==1.6
robotframework-httplibrary==0.4.2
robotframework-jsonlibrary==0.3.1
robotframework-requests==0.6.2
robotframework-ride==1.7.3.1
robotframework-selenium2library==3.0.0
robotframework-seleniumlibrary==4.1.0
robotframework-sshlibrary==3.4.0
robotframeworklexer==1.1
scp==0.13.2
selenium==3.141.0
six==1.13.0
soupsieve==1.9.5
tox==3.0.0
urllib3==1.25.7
virtualenv==16.7.7
waitress==1.3.1
WebOb==1.8.5
WebTest==2.0.33
wxPython==4.0.7.post2
zipp==0.6.0

您能否给出获得上述输出的解决方案。

这是1.0.0的文档

Read CSV As Dictionary
关键字文档如下:

将CSV作为字典阅读

Arguments:
    Filepath
    Name of key column
    Name(s) of value column(s)
    Delimiter (optional)
Returns:
    A dictionary with the key column a key and the value column(s) as value. 
    If there are multiple value columns the value will be a list containing all values.
例如:

*** Settings ***
Library  CSVLib    
*** Test Cases ***
Test CSV
    ${singlelist}=      Read CSV As Single List     test.csv
    log to console      ${singlelist}    
    ${list}=        read csv as list        test.csv
    log to console      ${list}    
    ${dict}=        read csv as dictionary      test_dict.csv       Animal      Legs        ,
    log to console      ${dict}    
    ${value}=       create list         Legs            Eyes
    ${dictWList}=       read csv as dictionary      test_dict1.csv      Animal      ${value}    ,
    log to console      ${dictWList}

下面是1.0.0的文档

Read CSV As Dictionary
关键字文档如下:

将CSV作为字典阅读

Arguments:
    Filepath
    Name of key column
    Name(s) of value column(s)
    Delimiter (optional)
Returns:
    A dictionary with the key column a key and the value column(s) as value. 
    If there are multiple value columns the value will be a list containing all values.
例如:

*** Settings ***
Library  CSVLib    
*** Test Cases ***
Test CSV
    ${singlelist}=      Read CSV As Single List     test.csv
    log to console      ${singlelist}    
    ${list}=        read csv as list        test.csv
    log to console      ${list}    
    ${dict}=        read csv as dictionary      test_dict.csv       Animal      Legs        ,
    log to console      ${dict}    
    ${value}=       create list         Legs            Eyes
    ${dictWList}=       read csv as dictionary      test_dict1.csv      Animal      ${value}    ,
    log to console      ${dictWList}

你说的关键词是什么意思?方法?请发布代码,您在其中读取csv,以及使用Python 3.7时出现的错误。在Python 27中,我使用了csvlibrary==0.0.2 csvlibrary(0.0.2)中有一个关键字将csv文件读取为关联,以便将csv文件作为字典读取。我的代码是
@{dict}=Read Csv File To Associative${File name}delimiter=,
。在python 37中,不支持上述Csv库版本。我正在使用SVLIB1.0.0。它包含以下关键字
将CSV读取为单个列表将CSV读取为列表将CSV读取为字典
如果我将关键字回复为将CSV读取为字典,我如何给出此关键字的参数关键字的含义是什么?方法?请发布代码,您在其中读取csv,以及使用Python 3.7时出现的错误。在Python 27中,我使用了csvlibrary==0.0.2 csvlibrary(0.0.2)中有一个关键字将csv文件读取为关联,以便将csv文件作为字典读取。我的代码是
@{dict}=Read Csv File To Associative${File name}delimiter=,
。在python 37中,不支持上述Csv库版本。我正在使用SVLIB1.0.0。它包含以下关键字
将CSV读取为单个列表将CSV读取为列表将CSV读取为字典
如果我将关键字回复为将CSV读取为字典,我如何给出此关键字的参数是。。但是我不知道如何为这个关键字提供参数。您能告诉我如何为这种类型的csv文件提供参数吗<代码>身份证,姓名,年龄,身高,体重1,爱丽丝,20,62120.6 2,弗雷迪,21,74190.6 3,鲍勃,17,68120.0我希望字典是
{'age':'20','height':'62','id':'1','weight':'120.6','name':'Alice'}{'age':'21','height':'74','id':'2','weight':'190.6','name':'Freddie'}{‘年龄’:‘17’、‘身高’:‘68’、‘身份证’:‘3’、‘体重’:‘120.0’、‘姓名’:‘鲍勃’}
我很确定,单靠一个关键字调用是不行的,因为输入的第一行是键。很可能你必须获取输入,然后从输入的第一行循环并构造键。是的..但我不知道如何为这个关键字提供参数。你能说我如何为这种类型提供参数吗是csv文件的。
id,name,age,height,weight 1,Alice,2062120.6 2,Freddie,2174190.6 3,Bob,1768120.0
我希望字典是
{'age':'20','height':'62','id':'1','weight':'120.6','name':'Alice'}{'age':'21','height':'74','id':'2','weight':'190.6','name':'Freddie'}{'age':'17','height':'68','id':'3','weight':'120.0','name':'Bob'}
我很确定,仅仅通过一个关键字调用是不行的,因为输入的第一行是键。很可能您必须获取输入,然后从输入的第一行循环并构造键。