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

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.

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.

1 Like

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


I also have habitually used data.Stairhandler.next() for staircases. I will use .__next__() for now for that too.

I think trials.next() should be working again in 3.0.6 and 3.0.7