The issue isn’t with PsychoPy here
Python is a very flexible language, but we as programmers need to be very aware of what types our objects are: Python will be very flexible until it suddenly gets very fussy.
I got lost a little bit lost with the errors, as clearly at one point you were still doing this:
thisExp.addData('Target0', Target0)
and as noted, we only want to try to save simple types (like numbers and strings) in the datafile, not complex objects like image stimuli (this is causing all sorts of complex memory copying and so on and leading to errors). Removing that alone should help things. But later you show an that you are using:
thisExp.addData('Target0', Target0.name)
but it isn’t clear where or when that occurs (in a different run with the problem above removed)?
Again, what you want is some debugging strategies. Along with simple print()
statements, you can use the type()
function to check what an object is. i.e. at various points in your code, is the object you are dealing with what you think it is? e.g.
print(type(Target0))
Use this after you create Target0
and potentially at points afterwards, to see why it isn’t the ImageStim that you think it should be. e.g. maybe somehow it comes out as an array of length 1, and you just need to extract it from that array? I can’t tell without seeing the code.