Search code examples
pythonvariablessikuli

How to tell if a variable is a string or a list, or etc in SIkuli?


I would like to check if variable is a string or a list, or etc in Sikuli? I mean variables that are currently been used in the IDLE.


Solution

  • Usually in Python, you can use type(varName) to determine the variable type. Sikuli however, is using type() for a different purpose and hence another method should be used. There are few options.

    1. isinstance().
    2. matches.__class__
    3. Just by printing the value. In many cases it is easy enough to see what type the variable is just by printing it. For example, if the variable is printed with [] - that's a list, {} - dictionary, etc...

    Example:

    >>> lst1 = ['a', 'b', 'c']
    >>> isinstance(lst1, list)
    True
    >>> lst1.__class__
    <type 'list'>