Skip to main content
 首页 » 编程设计

python之如何在 Sikuli 中使用 “type” 函数检查变量类型

2024年11月01日8bonelee

Sikuli 有自己的函数 type 用于打字。有什么方法可以调用 python (jython) 函数 type 吗?无法导入模块 builtins。当然,我可以改用 isinstance,但我只是好奇是否有可能超出 Sikuli 范围并调用非“覆盖”的 python 内置 type 函数。我用的是 Sikuli r930。

#import builtins                         #ImportError: No module named builtins 
findAll("1369036502514.png") 
matches = getLastMatches() 
print(isinstance(matches,Finder))        #returns TRUE 
type("1369035684637.png",'hello world')  #types characters  
type('hello world again')                #types characters  
print(type(matches))                     #TypeError: type(): 1st arg can't be coerced to String 

运行 builtins.type 也会导致失败:

builtins.type(matches) 
NameError: name 'builtins' is not defined 
 
__builtins__.type(matches) 
NameError: name '__builtins__' is not defined 

请您参考如下方法:

您可以使用matches.__class__。