Imported script cannot resolve 'Key' constant --- needs: from sikuli import *

Asked by Chris at Aviary

I have an imported script called blur.sikuli. When I run this on its own, I have no problems.

there is a line:

    type(Key.F5)

That I use to refresh the page.

If I import this script from another script (main.sikuli) in the same directory, it does not consider Key to be defined.

NameError: global name 'Key' is not defined

Is this a namespace issue? Seems like it should be safe to do without having to import all of my functions as global

Code:

blur.sikuli
---------------
def blurOperation():
    click("Blur")
    wait("Blur-1.png")
    click("1319653625110.png")

    assert exists("1319728623722.png")

def blur(self):
    type(Key.F5)
    wait("FIvnuwILHQCA.png")
    blurOperation()

#blur()

main.sikuli
----------------
import blur
blur.blur()

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
Best RaiMan (raimund-hocke) said :
#1

imported Sikuli scripts need an
from sikuli import *

at the beginning.

(... as mentioned in the docs ;-)

Revision history for this message
Chris at Aviary (i5lib) said :
#2

Thanks for the response. I had tried that and it didn't seem to have an effect. Shutting down the IDE and restarting it seems to do the trick, maybe some weird caching is going on.

Revision history for this message
Chris at Aviary (i5lib) said :
#3

Thanks RaiMan, that solved my question.