Accessing Sub Dictionary Key-Value To Manipulate

2,488 views
Skip to first unread message

Nesat Ufuk

unread,
Jul 3, 2015, 4:50:42 AM7/3/15
to robotframe...@googlegroups.com
Hi all,

I have been using robot framework 2.9b1 for two day and new dictionary &{dict} variable type is saved my time.

My question is how to access a sub dictionary item (in my case '1':'Example')  like below.

&{data}={'sale_data' :
{'submerchantname' : 'submerchant',
                    'subfield1':
                    {'mddFields' :
                    {'1': 'Example',
                    '2': 'two',
                    '3': 'three',
                    '9': 'nine'}
},
                    'payment_methods' : 'credit'
                }
}

I have tried &{data.1} or &{data.sale_data.subfield1.mddFields.1} but those did not work.

Thanks,
Nesat  

Pekka Klärck

unread,
Jul 3, 2015, 5:19:49 PM7/3/15
to nes...@gmail.com, robotframework-users
2015-07-03 11:48 GMT+03:00 Nesat Ufuk <nes...@gmail.com>:
>
> I have been using robot framework 2.9b1 for two day and new dictionary
> &{dict} variable type is saved my time.

Great to hear this new feature is useful!

> My question is how to access a sub dictionary item (in my case
> '1':'Example') like below.
>
> &{data}={'sale_data' :
> {'submerchantname' : 'submerchant',
> 'subfield1':
> {'mddFields' :
> {'1': 'Example',
> '2': 'two',
> '3': 'three',
> '9': 'nine'}
> },
> 'payment_methods' : 'credit'
> }
> }
>
> I have tried &{data.1} or &{data.sale_data.subfield1.mddFields.1} but those
> did not work.

The problem is not with nested dictionaries, they work just like you tried.

This dot-access uses Python's attribute access and attribute names
must be valid Python identifiers. Such an identifier cannot start with
a number and thus `mddFields.1` doesn't work. If you cannot rename the
key, you can switch to accessing values like `&{mddFields}[1]`.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Nesat Ufuk

unread,
Jul 7, 2015, 3:33:52 AM7/7/15
to robotframe...@googlegroups.com, nes...@gmail.com
Thank you Pekka,

How about assign a value to the key '1' ?
I have tried,
Set To Dictionary   ${data}   &{mddFields}[1]=new value

But I got,
Keyword 'Collections.Set To Dictionary' expected at least 1 non-keyword argument, got 0.

Thanks again,
Reply all
Reply to author
Forward
0 new messages