[open] Global/local variables and lists
I'm a bit confused about the local/global variable stuff. At the moment, I'm coding three inline_scripts that create random lists, draw from one of them, and use the drawn item for another task, respectively. They are all part of the same trial sequence. In the first script, variables and lists are defined and set globally, and are then used in the two latter scripts.
Here's the first script:
import random global list1, list2, random list =  # create empty list # append five 1s and 2s to the list: for i in range(5): list.append(1) list.append(2) # define shuffle list function, which takes a list as its argument: def shuffleList(list): L = list[:] # copy the input list random.shuffle(L) # and shuffle the copy return L # return shuffled copy # create 2 shuffled lists: list1 = shuffleList(list) list2 = shuffleList(list)
My questions are:
1) Am I correct in assuming, that I only need exp.set or exp.get if I wish to use these variables and lists in other items, outside this sequence?
2) How come I need to declare random global in order to use it in my shuffleList function?