How to save the images in the script folder , if they are not referenced by direct names in the script

Asked by Anshu

I have , say, about 20 baseline images for the script and named as , Page 1,Page 2,Page 3 etc.
So i just have a loop in the script to verify those and i am referring those using variable , instead of direct name.

So something like
baselline = "Page" + str(num) +".png" # where num is the counter and gets values 1,2,3....

Only problem is since there is no reference to "Page1.png" in the script , when i capture the images and save the script - the baseline images get deleted from the folder.

My workaround is to save those images in a separate folder and use then with reference to path .But is there simpler way to have them saved inside the same script folder ??

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:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Since you capture and name the images by hand in your script, just leave the strings (thumbnails one per line) where they are after the capture. If you like, you may move the strings to the end of the script and/or form a tuple, to save lines.

--- e.g. one per line:
"page1.png"
"page2.png"
...
"page20.png"

--- e.g. as tuple:
("page1.png", "page2.png", "page3.png", .... , "page20.png")
after a comma a newline is possible if you want

--- If you name the tuple, your loop becomes even easier:
myImages=("page1.png", "page2.png", "page3.png", .... , "page20.png")
for img in myImages:
   click(img)

--- or if you need the counter:
for n in range(len(myImages)):
   click(myImages[n])
   if n == 7:
      # do something special

Revision history for this message
Anshu (anshu-ca) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Anshu (anshu-ca) said :
#3

Thanks RaiMan,

Saving the image lines as the tuple - at the end of script ( and probably as a commented line) works in my script.

Thanks for quick reply as usual.
Anshu