I am trying to implement this repetitive block of code below, by creating objects with name fetched from a list instead of creating objects and passing instance repeatedly .
class waittill:
def __init__(self,path):
self.imagepath = os.path.join("C:\python\python_projects\pyautogui\images", path)
loaded=waittill("loaded.png")
agree=waittill("agree.png")
firstname=waittill("firstname.png") #This works absolutely fine
loginid=waittill("loginid.png") #I wish repetition could be avoided
password=waittill("password.png")
loginbutton=waittill("loginbutton.png")
customerlist=waittill("customerlist.png")
loginpage=waittill("loginpage.png")
customerinfo=waittill("customerinfo.png")
profile=waittill("profile.png")
is it possible to write a more elegant code, like cycling through an list to create objects
images=["loaded.png","agree.png","firstname.png","loginid.png","password.png","loginbutton.png","logout.png","middlename.png","lastname.png","submit.png",\
"customerlist.png","loginpage.png","customerinfo.png","profile.png"]
for each_image in images:
a,b=each_image.split(".")
b=(a+"."+b)
image=b.strip()
name=a.strip()
name=waittill(image) #this is where the problem lies, its repeatedly naming the object *name* and not say *loaded* or *agree*.