kgalford1
kgalford1

Reputation: 33

PyCharm Python - Display __str__ of object instead of memory address in debugger

As far as I remember, in IntelliJ, the debug window has the option to view the toString() of an object instead of its memory address. Is there a way to do this in PyCharm with an object's __str__(self)?

enter image description here

enter image description here

Upvotes: 3

Views: 1372

Answers (2)

Peter Trcka
Peter Trcka

Reputation: 1531

Pycharm in variable view / debugging is showing __str__ object representation instead of __repr__.

Here was created a work-item on JetBrains website. Unforunetally I think there is still no progress.

Upvotes: 2

DeepSpace
DeepSpace

Reputation: 81654

This should be done with __repr__:

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

f = Foo()
pass # breakpoint here

This shows 'foo object' in the debugger's variables window.

Upvotes: 3

Related Questions