Is there a way to check whether function output is assigned to a variable in Python?

前端 未结 7 907
[愿得一人]
[愿得一人] 2021-01-22 14:31

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

相关标签:
7条回答
  • 2021-01-22 15:23

    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.

    0 讨论(0)
提交回复
热议问题