import library ImportError: No module named library

Asked by Loren Lai

Hi @all,

what do I do wrong here?
Look, I have 2 files in the same directory (file1.sikuli , file2.sikuli)

#in file1.sikuli
----------------------
from sikuli import *

def startApp():
    click(loginButton)
    click(userField)
    type('user')
    click(pwdField)
    type('pwd')

def stopApp():
    click(logout)

#in file2.sikuli
----------------------
import file1

startApp()
wait(2)
find(myButton)
click(myButton)
....

stopApp()

OK, when I start to run the file2.sikuli in SIKULI-IDE I got the error message "import library ImportError: No module named file1"
What do I do wrong here ? All I want is to have 2 seperated sikuli-scripts . One ist my library (file1.sikuli) and the other one (file2.sikuli) is my main Application where I start my test.

Could you help or have any idea ?

Thank you in advance

Cheers
Loren

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Loren Lai
Solved:
Last query:
Last reply:
Revision history for this message
Loren Lai (lorenlai) said :
#1

I forgot to tell ...
I use Sikuli-IDE version 0.10.1

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

this kind of import is only supported starting with version 1.0RC3.

But why do you use such an old version.
recommended: version 1.0.1

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

One more thing:
if it works, you must either use

import file1
and
file1.startApp()

or
from file1 import *
and
startApp()

Revision history for this message
Loren Lai (lorenlai) said :
#4

Hello Raiman,

first of all thank you very much for your answering :-)
It works now !!! :-)))))

Just one more question please ...

now, in my mainApp() where I do import all other sikuli-scripts, e.g.

#filename: mainApp()

import file1
import file2
import file3

file1.callFunc1()
file2.callFunc2()
file3.callFunc3()

#Question: is there a better way how to import all the sikuli-files (file1, file2, file3, ...) with 1 line code ?
I mean, if I have 50 other sikuli scripts, so I will have 50 line codes for only "import" ;-)
That would not be nice ...

Thank you.

Cheers

Loren

Revision history for this message
obiwan-92 (obiwan-92) said :
#5

Hello,

Just to be clear, you can put several functions in one file, it will reduce the numbers of import to do.

To import with only one line :
import file1, file2, file3

Hope it's help.
Regards

Revision history for this message
Loren Lai (lorenlai) said :
#6

Hello Obiwan,

OK, it works ;-)
Thank you very much.

Cheers

Loren