Lambda for loop weirdness

Hey,

So I have this small chunk of code:

the variable docs is a list full of string file names and the idea of the code is it is supposed to make a new button and add it to the buttons list, set its on_press attribute to the OpenFile method (passing in the local variable d) and then displaying it on the last line.

The problem is the program seems to be remembering the variable d being passed in instead of its value.

This means that they all pass in the last element of the docs list because that’s what d is equal to after the loop ends. Can anyone help?

(The module I am using for this is Kivy but I think the problem is just regular python so you shouldn’t need to know it)