When using a for loop for a fixed list, type() is only the first letter

Asked by Matt Brown on 2019-01-02

Hello,

When I use a for loop with a fixed list, when accessing the current item with `entry`, only the first letter of `entry` appears be typed using `type()`.

Is there an issue with type() or an issue with my syntax?

    myListFixed = ("insomuchas")
    for entry in myListFixed:
      type(entry)

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-01-02
Last query:
2019-01-02
Last reply:
2019-01-02
Best RaiMan (raimund-hocke) said : #1

myListFixed = ("insomuchas")

... just is the list of characters in the given string

myListFixed = ("insomuchas", )

makes a list with 1 string as entry.

Has nothing to do with that problem, but be aware of the restrictions of type() (see docs)
paste() might be the better choice.

Matt Brown (matthewbrown) said : #2

Ahh hah! Excellent.

Is there a way to strongly type this is a string array so I don't run into this issue?

Of course, single string was intended as a test.

Matt Brown (matthewbrown) said : #3

Thanks RaiMan, that solved my question.

Matt Brown (matthewbrown) said : #4

In re to #2, quite obviously a lack of understanding of collections in python. Using a list `()` versus a set `[]` so that redundant entries can be contained therein. Thanks!

RaiMan (raimund-hocke) said : #5

Python generally is not strongly typed, hence type is evaluated from context on assignment.
... and variables can change their type at any time.

BTW: ("foo",) is not a list but a tuple and immutable.

The problem: the brackets ( ) syntactically are expression delimiters and the tuple itself is "foo",

a list (mutable) is defined as:
aList = ["foo"]

or
aList = []
aList.append["foo"]

please consult the Python docs or a basic tutorial if you plan to do more complex things.
Be aware: the interpreter is Jython 2.7 (since SikuliX is Java based)