error occurs when importing the files in the same directory

Asked by omsakthi

Hi,

I having two files in the same directory. i want to import a file to another. so i have followed your instrunction which is given in the Sikuli documentation .
 but one error is occuring when importing a file. The error is

[error] Error message: Traceback (most recent call last):
 File "E:\DOCUME~1\oramu\LOCALS~1\Temp\sikuli-tmp3479052429520681513.py", line 7, in
 Function.test(str);
 File "D:\Test\Function.sikuli\Function.py", line 5, in test
 click("1336642874695.png")
NameError: global name 'click' is not defined

my source code in Function.sikuli is

from sikuli.sikuli import*
def test(n):
 a=img5
 for n in range (0,8):
    click("img1")
     wait(10)
    click("img2")
    click("img3')
    wait(15)
    click("img4")
    click("img5")

source code for imported file has

import os
myScriptPath = "D:\\function\\Function"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import Function
find("1337158339156.png")
Function.test(str)

please give your suggestion for this

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:

This question was reopened

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

should be
from sikuli import *

or (deprecated)
from sikuli.Sikuli import *

Revision history for this message
omsakthi (r-sakthi08) said :
#2

the same error occurs when using
from sikuli iimport*

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

I cannot see your directory structure, so here the principal:

# main.sikuli (in whatever directory)
# ...
myScriptPath = "D:\\function\\Function"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import Function
# ...
Function.test(str)

# Function.sikuli (in directory D:\function\Function)
from sikuli import *
def test(str)
# ...

If main.sikuli and Function.sikuli are in the same directory, the sys.path stuff is not needed.

Revision history for this message
omsakthi (r-sakthi08) said :
#4

ya i have removed this line
from my script main.sikuli

  # if not myScriptPath in sys.path: sys.path.append(myScriptPath)

till i recieve the same error

Revision history for this message
omsakthi (r-sakthi08) said :
#5

ya i have removed this line
from my script main.sikuli

 # if not myScriptPath in sys.path: sys.path.append(myScriptPath)

till i recieve the same error

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

But it seems, that the 2 .sikuli are not in the same directory:

D:\Test\Function.sikuli\Function.py

and

myScriptPath = "D:\\function\\Function"

So were exactly are your files?

Revision history for this message
omsakthi (r-sakthi08) said :
#7

sorry i mentioned the wrong directory name in source code of
main .sikuli in the above

but i am using the coorect directory name in my code

import os
myScriptPath = "D:\\Test\\Function"
# if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import Function
find("1337158339156.png")
Function.test(str)

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

Hope this is the cause:
The directory containing your .sikuli should not be named like one of the .sikuli when using import (minor bug ;-).

Revision history for this message
omsakthi (r-sakthi08) said :
#9

Thanks RaiMan, that solved my question.