← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #694329]: define import and call it randomly?

 

Question #694329 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/694329

Ben Dix posted a new comment:
ok, sorry for talking to myself 😄
but proudly presenting a solution, working in theory and also in a different IDE environment (importing py files) so far:

import random

scriptlist = ['Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9']
print("These are the scripts I want to execute " , scriptlist)
Test1 = scriptlist[0]
Test2 = scriptlist[1]
Test3 = scriptlist[2]
Test4 = scriptlist[3]
Test5 = scriptlist[4]
Test6 = scriptlist[5]
Test7 = scriptlist[6]
Test8 = scriptlist[7]
Test9 = scriptlist[8]

def selectScript():
	if scriptlist[0] is Test1:
		Test1import()
	else:
		()
	if scriptlist[0] is Test2:
		Test2import()
	else:
		()
	if scriptlist[0] is Test3:
		Test3import()
	else:
		()
	if scriptlist[0] is Test4:
		Test4import()
	else:
		()
	if scriptlist[0] is Test5:
		Test5import()
	else:
		()
	if scriptlist[0] is Test6:
		Test6import()
	else:
		()
	if scriptlist[0] is Test7:
		Test7import()
	else:
		()
	if scriptlist[0] is Test8:
		Test8import()
	else:
		()
	if scriptlist[0] is Test9:
		Test9import()
	else:
		()

def Test1import():
	import Test1

def Test2import():
	import Test2

def Test3import():
	import Test3

def Test4import():
	import Test4
	
def Test5import():
	import Test5
	
def Test6import():
	import Test6
	
def Test7import():
	import Test7
	
def Test8import():
	import Test8

def Test9import():
	import Test9

def Test10import():
	import Test10

random.shuffle(scriptlist)
print("So I shuffled them to a new order " , scriptlist)
selectScript()
print("then I'll pick always the first of the list to execute it and then remove the first of that list")
print("The first script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The second script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The third script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 4. script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 5. script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 6. script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 7. script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 8. script to take would be " + scriptlist[0])
scriptlist.pop(0)
selectScript()
print("The 9. script to take would be " + scriptlist[0])
scriptlist.pop(0)


resulting in:


These are the scripts I want to execute  ['Test1', 'Test2', 'Test3', 'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9']
So I shuffled them to a new order  ['Test3', 'Test6', 'Test4', 'Test7', 'Test9', 'Test2', 'Test8', 'Test5', 'Test1']
say hello to my friends - this is the Test3  script-------------------------------------------------------3-3-3--3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3-3
then I'll pick always the first of the list to execute it and then remove the first of that list
The first script to take would be Test3
say hello to my friends - this is the Test6  script-------------------------------------------------------6-6-6--6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6-6
The second script to take would be Test6
say hello to my friends - this is the Test4  script-------------------------------------------------------4-4-4--4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4-4
The third script to take would be Test4
say hello to my friends - this is the Test7  script-------------------------------------------------------7-7-7--7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7-7
The 4. script to take would be Test7
say hello to my friends - this is the Test9  script-------------------------------------------------------9-9-9--9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9
The 5. script to take would be Test9
say hello to my friends - this is the Test2  script-------------------------------------------------------2-2-2--2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2
The 6. script to take would be Test2
say hello to my friends - this is the Test8  script-------------------------------------------------------8-8-8--8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8
The 7. script to take would be Test8
say hello to my friends - this is the Test5  script-------------------------------------------------------5-5-5--5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5-5
The 8. script to take would be Test5
say hello to my friends - this is the Test1  script-------------------------------------------------------1-1-1--1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1
The 9. script to take would be Test1


😄

now trying to implement this to sikuli 😄

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.