psychopy.org | Reference | Downloads | Github

How to get the current routine name via code?

Does anybody know how to get a name of current routine with a code? I assume it’s some attribute of Window object, but have not found the way to get it…

import sys
sys._getframe().f_code.co_name

Check out this thread:

https://stackoverflow.com/questions/5067604/determine-function-name-from-within-that-function-without-using-traceback/5067654

Maybe there are terminology issues here, but a “routine” in Builder code is not really a “thing” i.e. it isn’t some sort of object. It’s just a section of code in which certain things happen. In the graphical interface, routines have names, but that is just a representation for the user’s convenience. If you look at the generated script, you won’t see the name of the routine appear anywhere except in comments. Components within routines are objects with names, but the routine itself is just the section of code in which those components operate.

But since this may just be some terminology confusion, perhaps you need to describe what the problem is that you’re trying to solve.

Thanks @Michael, you are correct. I have deleted the post to reduce confusion, but thank you for clarifying things :slight_smile:

1 Like