psychopy.org | Reference | Downloads | Github

What happened to trials.next() and trials.nextEntry()?


#1

For years, to advance my trialHandler I’ve used .next()
However, that no longer works, even though the trialHandler documentation says “Calls to .next() will fetch the next trial object”.

Elsewhere in Psychopy3 documentation, e.g. ExperimentHandler, I’ve seen mention of “.nextEntry”, but that also doesn’t work with trialHandler, as you can see in my code snippet here.

The examples all have trialHandler advanced via a for loop, which is why Psychopy passes automated testing I suppose, but sometimes I need to have advancing to the next trial contingent on things which makes a for loop unsuitable.


#2

About two years ago, from the look of things, the .next() function got turned into .__next__() to avoid conflicts with a different .next() function. If you add the underscores it should work. The documentation was never updated.


#3

Ah, thanks for working this out Jonathan. I didn’t recall this being removed but it’s because it was done by the conversion process into Python3 compatibility.

For a bit further explanation, next() methods were renamed __next__() in Python3 because in most cases the user didn’t need to see the existence of the method. It fits with the general existence of various special methods that the user doesn’t directly need. That kind of makes sense, but I think our TrialHandlers (and related classes) do actually benefit from a visible next() function, which is why Alex is now wanting it and why it was documented.

Rather than fixing the documentation, I think we should add an alias so that the next() exists again, as suggested here https://stackoverflow.com/questions/29578469/how-to-make-an-object-both-a-python2-and-python3-iterator