且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从函数返回后,如何在 Python 中打印原始变量的名称?

更新时间:2023-12-04 10:30:28

简短回答:没有.

长答案:使用回溯、检查等进行一些丑陋的黑客攻击是可能的,但通常可能不建议将其用于生产代码.例如见:

Long answer: this is possible with some ugly hacks using traceback, inspect and the like, but it's generally probably not recommended for production code. For example see:

也许您可以使用一种解决方法将值转换回名称/表示字符串.如果您发布更多示例代码和有关您想要此内容的详细信息,也许我们可以提供更深入的帮助.

Perhaps you can use a workaround to translate the value back to a name/representational string. If you post some more sample code and details about what you're wanting this for maybe we can provide more in-depth assistance.