Sikuli type() vs python\jython type() commands --- use isinstance() instead

Asked by Eugene S

Hi,

Since "type()" is a valid Sikuli command (for typing in text), it seems that there is no way to use the Python/Jython built-in type() command (for determining variable type).

Is there any solution\workaround that will enable to use regular Python type() command?

Thanks,
Eugene

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
obiwan-92 (obiwan-92) said :
#1

Hi.
Of course, you can.
Try this :

import __builtin__ as __builtin__
print __builtin__.type(12)
print __builtin__.type('abc')

Regards.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#2

the best workaround is to avoid type() and use is instance()

Revision history for this message
Eugene S (shragovich) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
tranquillo (rob-tranquillo) said :
#4

instance() does not work:
[error] NameError ( name 'instance' is not defined )

Revision history for this message
RaiMan (raimund-hocke) said :
#5

@tranq....
read again:
isinstance()

Revision history for this message
tranquillo (rob-tranquillo) said :
#6

i read again, and see same like before "is<space>instance()" ;-)
But now find it.

Thank you very much

Revision history for this message
RaiMan (raimund-hocke) said :
#7

@tranquillo
not sure where and what you read:
see: https://docs.python.org/2/library/functions.html#isinstance

Revision history for this message
Alex Lunyov (lunyov-av) said :
#8

I had the same problem (and solved for my task). Please, let me know it this workaround is bad for any reason:

sikulitype = type # save sikuli type function
del type # delete it to return to native Python function
pythtype = type # save native function
type = sikulitype # return to Sikuli common type() function

print pythtype(pythtype) # works as expected, gives Python type() result
type("OK") # as usual Sikuli typing

// comments for the Sikuli/Python beginners :)