【问题标题】:PyCharm Python - Display __str__ of object instead of memory address in debuggerPyCharm Python - 在调试器中显示对象的 __str__ 而不是内存地址
【发布时间】:2022-01-15 05:39:46
【问题描述】:

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

【问题讨论】:

    标签: python pycharm


    【解决方案1】:

    这应该使用__repr__

    class Foo:
        def __repr__(self):
            return 'foo object'
    
    f = Foo()
    pass # breakpoint here
    

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

    【讨论】:

      【解决方案2】:

      变量视图/调试中的 Pycharm 显示 __str__ 对象表示,而不是 __repr__

      Here 在 JetBrains 网站上创建了一个工作项。不幸的是,我认为仍然没有进展。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-26
        • 2021-05-18
        • 1970-01-01
        • 1970-01-01
        • 2010-11-15
        • 2018-01-02
        • 1970-01-01
        相关资源
        最近更新 更多