← Back to team overview

sikuli-driver team mailing list archive

[Question #144772]: Python style Dictionary, string as key

 

New question #144772 on Sikuli:
https://answers.launchpad.net/sikuli/+question/144772

This is how i got a normal python  dictionary to work with Sikuli. 


1) make and image library. i have created my like this:

from sikuli.Sikuli import *

ItemToBeClicked = 12345543.png   # aka the screen shot



2) create your main script that imports the images

from imageLib import *

class mytest():
__def __init__(self):
____self.myValues = { 'clickthis':ItemToBeClicked, 'someothervarable':ImageVarableName} #no " or ' around your values
____self.answer = None

__def whatToclick(self):
____self.answer=input("what should i click?")  # this is where you would type "clickthis".... aka your key value
____click(self.myValues.get(self.answer))

mt = mytest()
mt.whatToclick()



in short VDict is great for working with that image as your key. but if you want to work the other way/direction it's a bit harder. The why I'm showing allows a user to use a string as your key and and image variable as you value.

i don't hard code my path to image files because that reduces code re-usability(if that's a word... lol) and if i have to change screen resolutions then i have a separate file that allows easy of retaking pictures at a new resolution.


i'm posting this to show other users how to achieve this and to have it looked over to see if the code is correct in procedure.

let me know if there are any problems with my method of handling this.

thanks

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.