Yeah you cant assign values to a string. Thats what your program is trying to do. Well i would advise using a dictionary for this one:
d1 = {}
d2 = {}
for swipeload in range (0, 15, 1):
d1["E"+str(swipeload)+"_Path"] = os.path.join("data","E"+str(swipeload)+".gif")
d2["E"+str(swipeload)] = pygame.image.load("E"+str(swipeload)+"_Path")
This now has a dictionary where the string values are the keys and the values are what you want. The first dictionary holds the path while the second dictionary holds the image.
Hope that helps
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
I would suggest lists like this
cnt_img = 15
E_Path = [os.path.join("data", "E%d.gif" % k) for k in xrange(cnt_img)]
E = [pygame.image.load(E_Path[k]) for k in xrange(cnt_img)]
Then you can use E[k] and E_Path[k] to get the k-th image or path.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
mabey you could re-write it like this:
[code=python]
cnt_img = 15
E_Path = [os.path.join("data", "E%d.gif" % k) for k in xrange(cnt_img)]
E = [pygame.image.load(E_Path[k]) for k in xrange(cnt_img)]
cnt_img = 15 E_Path = [os.path.join("data", "E%d.gif" % k) for k in xrange(cnt_img)] = [pygame.image.load(E_Path[k]) for k in xrange(cnt_img)]
Now use E[k] and E_Path[k] to get the k-th image
tomtetlaw
Practically a Master Poster
605 posts since Sep 2008
Reputation Points: 9
Solved Threads: 5