Passing dictionary key with space

677 views
Skip to first unread message

Omer Nir

unread,
Jan 1, 2019, 2:46:24 AM1/1/19
to robotframework-users
Hi,

I'm using a YAML file to pass a dictionary:

SEARCH_PERSON:
    Name:
        - michael test
        - John Smith
    Work Place:
        - Facebook
        - Home

and getting this error:

Resolving variable '${PersonInfo.Work Place}' failed: SyntaxError: unexpected EOF while parsing (<string>, line 1)

tried to encapsulate with quotes and double quotes and even adding ${SPACE} between the words, with no luck.


any suggestions?

Anne kootstra

unread,
Jan 3, 2019, 2:41:09 AM1/3/19
to robotframework-users
Have you tried: ${PersonInfo.["Work Place"]? 

Kind regards,

Anne

Op dinsdag 1 januari 2019 08:46:24 UTC+1 schreef Omer Nir:

Omer Nir

unread,
Jan 3, 2019, 8:54:27 AM1/3/19
to robotframework-users
nope.


receiving this error:

failed: ConstructorError: while constructing a mapping

Pekka Klärck

unread,
Jan 3, 2019, 9:06:39 AM1/3/19
to Omer Nir, robotframework-users
ti 1. tammik. 2019 klo 9.46 Omer Nir (omni...@gmail.com) kirjoitti:
>
> Hi,
>
> I'm using a YAML file to pass a dictionary:
>
> SEARCH_PERSON:
> Name:
> - michael test
> - John Smith
> Work Place:
> - Facebook
> - Home
>
> and getting this error:
>
> Resolving variable '${PersonInfo.Work Place}' failed: SyntaxError: unexpected EOF while parsing (<string>, line 1)

This syntax uses Python's attribute access and fails because
attributes cannot contain spaces. The easiest solution is using the
item access syntax instead. There are basically two possibilities:

1. Use Robot's own syntax '${PersonInfo}[Work Place]'. Notice that
this requires RF 3.1 and with earlier you need to use
'&{PersonInfo}[Work Place]'. For more details see:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#accessing-list-and-dictionary-items

2. Use extended variable syntax (like you did earlier) and Python's
item access like '${PersonInfo["Work Place"]}'. Notice that now the
key needs to be quoted like in Python. For more details about the
extended variable syntax see:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#extended-variable-syntax

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

Omer Nir

unread,
Jan 6, 2019, 1:42:54 AM1/6/19
to robotframework-users
Pekka,

neither work...
Reply all
Reply to author
Forward
0 new messages