function not working

Asked by janani pavithra

{{main program:

exec open("c:\\users\\desktop\\my Functions\\square.sikuli\\square.py").read() #what does this do?
s=square(9)
print s

sub-program:

#I have stored the following in "desktop->my Functions->square.sikuli"

def square(x):
r=x*x
return r}}

is not working... why?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Don't use blanks and other special characters in your directory and file names you use in Sikuli. There are some problems.

to test your workflow put the following in one script:

def square(x):
   r=x*x
   return r
# since def: starts a new block, you have to indent the statements belonging to your function

print square(9)

this should work.

then you can put all your functions in one script, that you store in a central place:
myFunctions.sikuli.

At the beginning you use:
execfile("path-to-your-function-repository\\myFunctions.sikuli\\myFunctions.py")

this reads and executes all python code available in myFunctions.py (I prefer this to "exec open().read()")

On more comment:

you said:
#I have stored the following in "desktop->my Functions->square.sikuli"

and used:
c:\\users\\desktop\\my Functions\\square.sikuli\\square.py
as file name. I suppose you are windows, since you use \\
I think this is wrong, should be something like. if it is stored in the real windows desktop.
c:\\users\\yourName\\desktop\\my Functions\\square.sikuli\\square.py

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

One more comment:
If you have any problems, pls. give some info on the symptoms (what kind of error, error messages, ...)

Can you help with this problem?

Provide an answer of your own, or ask janani pavithra for more information if necessary.

To post a message you must log in.