How do I import a simple python module in my Sikuli script ?

Asked by Aravind

Hi,
I just want to display some messages in my command-line like that of the 'Zen of Python' being displayed if we have an 'import this' statement in our script. How can I accomplish that using just an import something.py. Tried putting one .py file which will display some texts in the Jython libs but didn't work out.
Also I'm curious to know from which path does the this.py gets imported in the Sikuli script. (since, eventhough I deleted the this.py from the libs folder in Jython, it worked) . I'm running the Sikuli script via the command-line using "runScript.cmd -r script"

Thanks

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

What version?

--- Tried putting one .py file ... in the Jython libs
what folder do you mean by "Jython libs"

--- from which path does the this.py gets imported in the Sikuli script
together with the support of being able to import .sikuli scripts (adding this to the iamge path too), the parent folder of the running script and the script folder itself are added to sys.path at the first import of a .sikuli.
hence the easiest way to import other Python snippets is to pack them in a .sikuli and have them in the same folder as the running script.
In all other cases you have to add appropriate entries in sys.path before.

Another general option to just execute some stored Python lines of code is to use
execfile("path-to-a-file-containing-python-code")
The code in the file is run in the context of the current script.

Revision history for this message
Aravind (a4aravind) said :
#2

I followed the first option and it worked. Got an idea of what is happening in the background as well. Thanks a lot for this info.

Revision history for this message
Aravind (a4aravind) said :
#3

Thanks RaiMan, that solved my question.