Building a loop in python
Hi,
In my file pool I have a bunch of images, all called <name>.jpg. I want to use each image with its corresponding name in a loop (basically, this is for the familiarisation phase of an experiment).
Given a list called filename and one called name, made like this:
# get all images in the file pool (all .jpg format)
filename = [image for image in pool if ".jpg" in image]
# images are named after their content, so these are the image names
name = [image.rsplit(".",1)[0] for image in filename
is there a way I can populate a loop datamatrix so that it looks as below, and then use it?
| name | filename |
|---|---|
| apple | apple.jpg |
| banana | banana.jpg |
| ... | ... |
Thanks in advance!
Comments
Hello,
Yes you can do it with DataMatrix:
http://osdoc.cogsci.nl/3.1/manual/structure/loop/
http://datamatrix.cogsci.nl/
The strategy I use (but there might be something better) is to get an inline at the very beginning of my script where I do stuffs to list (randomizing, name... whatever) and populate.
Then having a loop that is empty and sequential. Insert in this loop the sequence (classical).

Please find the script attached. Not sure if it is the best strategy but that is the one I use. I hope it helps.
Best,
Sylvain
Thanks Sylvain, that works perfectly