'KEY_WIN' is not defined in imported script --- add: from sikuli import *

Asked by Eugene S

I have a number of tests, each one in a separate file. In order to make these scripts more readable and clear I have decided to move some of the functionality to external file and import it as a module to each script. For example consider the following piece of code which I have moved to that module:

type("r", KEY_WIN)
 localLog.debug("WIN+R key pressed")
 paste(link)
 localLog.debug("%s pasted", link)
 type(Key.ENTER)
 localLog.debug("Enter pressed")

This is defined in the module as function "windowsRun(link)" so I when the module imported I should have been able to run it like that (assuming that the module name is "generics") :

generics.windowsRun(some_link)

When I run my main script it seems that the module is being recognized and imported properly however I end up with the following error:

NameError: global name 'KEY_WIN' is not defined

Any idea why this might happen?

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

as mentioned here:
http://doc.sikuli.org/globals.html#importing-other-sikuli-scripts-reuse-code-and-images

in section:
The prerequisites:

you need in the subs:
your imported script must contain (recommendation: as first line) the following statement: from sikuli import * (this is necessary for the Python environment to know the Sikuli classes, methods, functions and global names)

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

Yes of course! I completely forgot about that.
Thanks!

Not related to this specific issue but I see that all the logging which happen in the module is not being printed to the screen. Any idea why is that? (I can start a separate question)

Cheers,
Eugene

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

yes please a new question ;-)

... but it is not clear what you mean with
I see that all the logging which happen in the module is not being printed to the screen
logging ???
screen ???

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

Thanks RaiMan, that solved my question.

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

Hi RaiMan,

Sorry for the unclear question.
Anyway it was my mistake, not related to Sikuli. So everything is working as expected right now.

Thanks!
Eugene