If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Win 10 64 bit
PsychoPy version (e.g. 1.84.x): 3.1.2
Standard Standalone? (y/n) If not then what?:y
**What are you trying to achieve?:**I want to input a UUID.UUID4 into the participant field of the Experiment Settings pop up window
**What did you try to make it work?:**I tried the suggestions provided by first using “import uuid” in the code view (didn’t work) and in the Python commands code input (didn’t work). The import uuid disappears from Coder View when the program is run. The Python commands code input retains the import uuid and the code for inputting the uuid.uuid4 into the participant field. The code is ‘Participant’: str(uuid.uuid4()). I have tried it with a colon, an equal sign, and with square brackets. None of the combinations worked.
What specifically went wrong when you tried that?:
This window pops up without the uuid
followed by this error message:
NOTE: When I input the code into the Coder View and run it, it works perfectly. For some unknown reason I cannot get the code to work in the Builder View. Please help. I have submitted this problem before without a resolution. Any help would be appreciated.
Include pasted full error message if possible. “That didn’t work” is not enough information.
Hi @patricia,
The error in your error box is related to how you have changed the filename formatting in experiment settings. First, reset this back to the original value:
u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
For your problem there is a solution, but it requires that the participant does not see the actual participant number in the GUI (if required, it can be printed at some point in the experiment should the participant need to know this). To get your datafile to have a unique id, add a code component, and in the “Begin Experiment” tab, you change the value of the variable containing the datafile name:
import uuid # import first
# Simple name
filename = _thisDir + os.sep + 'data/' + str(uuid.uuid4())
# Datafile name including exp name and datetime
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (str(uuid.uuid4()), expName, expInfo['date'])
Note, this is for Python tasks and will not work in online studies.
What does your last line mean - “This is for Python tasks and will not work in online studies”.
Do you mean it will not work in Pavlovia?
I’m only using PsychoPy with the python code option.
This line of code gives an error unless I change ‘participant’ to ‘Participant’:
u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
I will let you know if it outputs correctly once I get the rest of the code working.
I mean, the Python modules that you are using, e.g., uuid, may not be available online, although it is probably a small change to get it working. Anyway, since you are not running online tasks, it does not matter.
The line of code will throw an error if the participant
key does not match exactly the participant field you have created in your Experiment Settings.
Thanks, that’s what I thought. You’ve been very helpful.
I will let you know if the participant output shows the uuid code. Still working on the rest of the code.