How do you split a word and make a list of its letters?

1,522 views
Skip to first unread message

antonio III cabreira

unread,
Nov 22, 2011, 10:10:58 AM11/22/11
to robotframework-users
Hi All,

Is there a keyword defined that can break a word and returns its
letters into a list? The list of letters would be used for the "Press
Key Native" keyword.

Thanks!

Jussi Malinen

unread,
Nov 24, 2011, 9:23:01 AM11/24/11
to robotframework-users
Hi Antonio!

I can't think of an existing keyword that would do that, but it is
very easy to do this in your own library.

1. create a file char_splitter.py and add this function there:

def split_chars(text):
return [c for c in text]

2. take this library into use

Library char_splitter.py

3. Profit!


- Jussi

--
Jussi Malinen / Robot Framework
Reaktor, www.reaktor.fi

> --
> You received this message because you are subscribed to the Google Groups "robotframework-users" group.
> To post to this group, send email to robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.
>
>

--
Jussi Malinen / Robot Framework
Reaktor, www.reaktor.fi

memoselyk

unread,
Nov 24, 2011, 12:27:06 PM11/24/11
to robotframework-users
On Nov 24, 8:23 am, Jussi Malinen <jussi.ao.mali...@gmail.com> wrote:
> Hi Antonio!
>
> I can't think of an existing keyword that would do that, but it is
> very easy to do this in your own library.
>
Or you could have that code direclty in your TC or as a User keyword.
Taking adavantage of built-in Evaluate keyword

${string} = | Set Variable | NOW WITH SPACES
@{chararr} = | Evaluate | [ ch for ch in '${string}' ]
:FOR | ${letter} | IN | @{chrarr}
| # Do something with the letter here

Note that I'm using a single quote to delimit the string so, if your
string contains a single quote this won't work.
You may use triple quotes, but again, this doesnt work if a string
ends in a quote.

Hope it helps...

>
> --
> Jussi Malinen / Robot Framework
> Reaktor,www.reaktor.fi
>
> On Tue, Nov 22, 2011 at 5:10 PM, antonio III cabreira
>
>
>
>
>
>
>
>
>
> <antonio.cabreira...@gmail.com> wrote:
> > Hi All,
>
> > Is there a keyword defined that can break a word and returns its
> > letters into a list? The list of letters would be used for the "Press
> > Key Native" keyword.
>
> > Thanks!
>
> > --
> > You received this message because you are subscribed to the Google Groups "robotframework-users" group.
> > To post to this group, send email to robotframe...@googlegroups.com.
> > To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.

> > For more options, visit this group athttp://groups.google.com/group/robotframework-users?hl=en.


>
> --
> Jussi Malinen / Robot Framework
> Reaktor,www.reaktor.fi

---
Guillermo

memoselyk

unread,
Nov 24, 2011, 12:06:20 PM11/24/11
to robotframework-users
Hi Antonio

On Nov 24, 8:23 am, Jussi Malinen <jussi.ao.mali...@gmail.com> wrote:

> Hi Antonio!
>
> I can't think of an existing keyword that would do that, but it is
> very easy to do this in your own library.
>

Or you could achieve the same with-in RF. In your TC or a User
Keyword.

${string} = | Set Variable | NOW WITH SPACES
@{chararr} = | Evaluate | [ ch for ch in '${string}' ]
:FOR | ${letter} | IN | @{chrarr}
| # Do something with the letter here

Note: That I'm using single quotes to delimit the string, so if your
string contains a single quote you'd get SyntaxError.

Hope it helps,
Guillermo

Pekka Klärck

unread,
Dec 12, 2011, 5:56:05 PM12/12/11
to antonio.c...@gmail.com, robotframework-users
2011/11/22 antonio III cabreira <antonio.c...@gmail.com>:

>
> Is there a keyword defined that can break a word and returns its
> letters into a list? The list of letters would be used for the "Press
> Key Native" keyword.

There were already good replies on how to implement such keyword
yourself. Adding such a keyword into Strings library [1] so please
submit an issue [2] about it. Strings actually already has `Split
String` but it requires a delimiter. It would probably be best to
implement new `Split String To Characters` keyword than trying to
enhance the old one somehow.

[1] http://code.google.com/p/robotframework/wiki/StringLibrary
[2] http://code.google.com/p/robotframework/issues/list

Cheers,
.peke

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

antonio III cabreira

unread,
Dec 13, 2011, 7:49:15 AM12/13/11
to Pekka Klärck, robotframework-users
I've tried Jussi's and Memoselyk's take on it and both ways worked. I ended up using the python list() function though. Thanks at least I know there are other options that I can use the next time I encounter this type of behavior.

I also filed this as an issue: 
Issue 1011:Add keyword 'Split String To Characters' keyword
Reply all
Reply to author
Forward
0 new messages