I think this cannot be done.
The debug mask you posted works because it expands before compilation during preprocessing when you know the name of the variable. It is like you are writing all these cout
yourself.
Python does not have a preprocessor (AFAIK), there are external tools that do the same thing (pyp and others), but you cannot define a macro with a standard language.
So you have to do your trick at runtime. Well, at run time, you donโt know the "name" of the variable, because the variable is just a reference to the object when you call the method that you call it on the object, not the "variable". There can be many variables pointing to this object, how does the object know which variable was used to call the method?
Andrea Spadaccini
source share