gpt4 book ai didi

python - PyCharm Python - 在调试器中显示对象的 __str__ 而不是内存地址

转载 作者:行者123 更新时间:2023-12-01 01:35:18 25 4
gpt4 key购买 nike

据我记得,在 IntelliJ 中,调试窗口可以选择查看 toString()对象的地址而不是其内存地址。有没有办法在 PyCharm 中使用对象的 __str__(self) 来执行此操作?

enter image description here

enter image description here

最佳答案

这应该使用__repr__来完成:

class Foo:
def __repr__(self):
return 'foo object'

f = Foo()
pass # breakpoint here

这会在调试器的变量窗口中显示'foo object'

关于python - PyCharm Python - 在调试器中显示对象的 __str__ 而不是内存地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52444262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com