When teaching #Python debugging recently, I've been using this:

>>> vars(some_obj)

Instead of this:

>>> some_obj.__dict__

Why?

1) I prefer high-level operations over direct dunder access when possible (e.g. str(x) over x.__str__())
2) It's two fewer characters 😆

Follow

@treyhunner I wish that the built-in vars worked with classes that don't have a `__dict__` (slotted classes). The best you can do is manually iterate through slots and use getattr with all of them but that's a hassle.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.