Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

after_experiment.py error

edited June 2016 in OpenSesame

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

  • edited 9:37PM

    Hi Erik,

    It took me a while to figure this one out, but the problem is that you're (inadvertently) shadowing the var object. The following line causes the problem:

    from numpy import *
    

    One thing that's imported is the numpy.var() function, which replaces OpenSesame's default var object in the Python workspace. This is called shadowing in Python. The after_experiment extension chokes on this, because it doesn't expect the var object to be a function.

    Workaround: Avoid wildcard (*) imports, which are generally bad practice, but rather do something like:

    import numpy
    three = numpy.sqrt(9)
    

    Or explicitly import only the things that you need:

    from numpy import sqrt
    three = sqrt(9)
    

    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

Sign In or Register to comment.