In Python, I\'d like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose
There is no way for a function to know how its return value is being used.
Well, as you mention, egregious bytecode hacks might be able to do it, but it would be really complicated and probably fragile. Go the simpler explicit route.