Hi everyone,
I ran into a small issue while trying to access the duration attribute of a keyboard component in code executed during the End Routine and I wanted to check whether this might be a bug or just intended behavior.
It seems that if no response is given in the first trial, the duration attribute does not exist, so attempting to access it raises an error. This can be handled with a safeguard like:
if hasattr(responseObject, "duration") and responseObject.duration is not None:
rds = responseObject.duration
else:
rds = []
However, in my case, this led to durations from the previous trial carrying over when no response was given in the current trial. I was able to fix this by explicitly resetting the attribute in Begin Routine:
responseObject.duration = []
That worked well for me, but it made me wonder whether this behavior is intentional. Therefore, I looked into the auto-generated code from Experiment Builder (PsychoPy3 v2026.1.3), and I noticed that it initializes several attributes in Begin Routine:
# create starting attributes for responseObject
responseObject.keys = []
responseObject.rt = []
_responseObject_allKeys = []
This seems just the code that I added manually, but duration is not included there.
If there is a reason why duration is not initialized the same way, feel free to ignore this! I just wanted to flag it since it caught me a bit off guard.
Thanks!