sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #08612
Re: [Question #187024]: How Can I use variables as part of a path
Question #187024 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/187024
Status: Open => Answered
RaiMan proposed the following answer:
Since we have the power of Python in Sikuli script, there is no need to
fiddle around with commands line windows.
Even for a novice, it is rather simple to get into it. And since you
know, how to do things with AutoHotKey, you are an expert in scripting
;-)
--- But lets have a look first on your approach:
type with special characters might not have worked anyway (faq 933)
Strings containing \ should be noted as raw strings r"some string with a \ backslash" or you have to double the slashes.
Numbers are casted to strings by str(number).
So your command string might look this way:
cmd = r"mkdir c:\data\"+ str(number) + name + r"\output" # you were near
by ;-)
but Python too has a powerful string formatter:
cmd = r"mkdir c:\data\%d%s\output"%(number, name)
The string becomes a template with %-placeholders, that are filled with the corresponding variables in the list %().
Now we could open a command line and paste the command and type a
Key.RETURN. This would work, but is much too complicated.
--- The Python way:
You might like it, if you like AutoHotKey ;-)
import os
os.mkdir(r"c:\data\%d%s\output"%(number, name) )
import statements should be once in the beginning of the script.
--- issue commands with Python
is rather easy with with os.popen(), especially in cases, where you want to get the command output back:
import os
out = os.popen(cmd ).readlines()
for line in out:
print line.strip()
where cmd is a string, containing something that can be run on a command
line.
If you rally want to do more stuff with Sikuli, it is a good investment
to get into the basics of Python. It is easier than AutoHotKey and with
the features of Sikuli much more powerful.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.