sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #01885
Re: [Question #150770]: Using random.choice with pictures
Question #150770 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/150770
Status: Open => Answered
RaiMan proposed the following answer:
you have to make a list (if it is dynamically appended) or a tuple (if
it is fixed) of these picture filenames (for Python-newbees: these are
mutable and immutable arrays)
--- e.g. tuple
import random
myImgs = (
"img1.png",
"img2.png",
"img3.png",
"img4.png",
"img5.png",
"img6.png",
"img7.png",
)
d = random.choice(myImgs)
click(d)
--- e.g. list
import random
import os
allFiles = os.listdir(getBundlePath())
myImgs = [] # empty list
for f in allFiles:
if not '.png' == os.path.splitext(f)[1]: continue
myImgs.append(f)
# myImgs should contain at least one entry!
d = random.choice(myImgs)
click(d)
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.