sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #21233
Re: [Question #236120]: How can I import variables used by my script from external files?
Question #236120 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/236120
Status: Open => Answered
RaiMan proposed the following answer:
-- to use import, the files must either be xxx.sikuli scripts or have
ending .py
-- If this is your plan, then the folder containing the file to import
must be on sys.path at time of import:
# outside the loop to get the index of the entry in sys.path:
import os
sys.path.add("__myfiles__")
sys_path_entry = sys.path.index("__myfiles__")
file_folders = "abolute_path_of_folderNN" # without the number!
# e.g. file_folder = r"c:\mystuff\folder"
-- the import can be created and executed:
exec "from %s import *"%current_file
where n is the current loop index
So the loop might look like this:
for n in range(number_of_configs):
current_folder = file_folder + str(n)
current_file = "config_file" + str(n)
sys.path[sys_path_entry] = current_folder
exec "from %s import *"%
# your other coding
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.