after_experiment.py error
Dear All,
I am writing up a N-back experiment (code), and had this error message upon the completion of the program:
Extension after_experiment misbehaved on event end_experiment (see debug window for stack trace)
In the debug window, it says:
Traceback:
File "dist\libqtopensesame\extensions\_extension_manager.py", line 113, in fire
File "dist\libqtopensesame\extensions\_base_extension.py", line 385, in fire
File "C:\Program Files (x86)\OpenSesame\extensions\after_experiment\after_experiment.py", line 48, in event_end_experiment
File "C:\Program Files (x86)\OpenSesame\extensions\after_experiment\after_experiment.py", line 107, in handle_success
File "C:\Program Files (x86)\OpenSesame\extensions\after_experiment\after_experiment.py", line 62, in logfile
TypeError: argument of type 'function' is not iterable
I am not quite sure which part of my code leads to this error. Any hint will be appreciated.
Thanks,
Erik Chang
Comments
Hi Erik,
It took me a while to figure this one out, but the problem is that you're (inadvertently) shadowing the
varobject. The following line causes the problem:One thing that's imported is the
numpy.var()function, which replaces OpenSesame's defaultvarobject in the Python workspace. This is called shadowing in Python. Theafter_experimentextension chokes on this, because it doesn't expect thevarobject to be a function.Workaround: Avoid wildcard (
*) imports, which are generally bad practice, but rather do something like:Or explicitly import only the things that you need:
But it's not great that you can break OpenSesame by doing this, of course. So I'll think a bit about the best way to make OpenSesame more robust to shadowing.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!