Join Nostr
2024-12-04 02:08:00 UTC

Trey Hunner 🐍 on Nostr: When debugging in #Python, I prefer this: >>> vars(some_obj) Over this: >>> ...

When debugging in #Python, I prefer this:

>>> vars(some_obj)

Over this:

>>> some_obj.__dict__

Why?

1. When possible, I prefer high-level operations over direct dunder access
2. It's 2 fewer characters!

And yes I also use dir(), but the two have slightly different uses and both can be handy!

More on dir & vars: https://pym.dev/inspecting-python-objects/