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/Published at
2024-12-04 02:08:00 UTCEvent JSON
{
"id": "aa3791394cbfd394e8448d7bbc49e228d298689b29235fefa896cb3229e87109",
"pubkey": "7e9159fbfd5526415c8d2de2e4c7654e3660883f9ccae720a70fa3c1f3cf1f45",
"created_at": 1733278080,
"kind": 1,
"tags": [
[
"proxy",
"https://mastodon.social/@treyhunner/113592112302808011",
"web"
],
[
"t",
"python"
],
[
"proxy",
"https://mastodon.social/users/treyhunner/statuses/113592112302808011",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mastodon.social/users/treyhunner/statuses/113592112302808011",
"pink.momostr"
],
[
"-"
]
],
"content": "When debugging in #Python, I prefer this:\n\n\u003e\u003e\u003e vars(some_obj)\n\nOver this:\n\n\u003e\u003e\u003e some_obj.__dict__\n\nWhy?\n\n1. When possible, I prefer high-level operations over direct dunder access\n2. It's 2 fewer characters!\n\nAnd yes I also use dir(), but the two have slightly different uses and both can be handy!\n\nMore on dir \u0026 vars: https://pym.dev/inspecting-python-objects/",
"sig": "3511188d5862fe8ff81501e022f356473f20535cdc91e6d743b13f4fdb81f54781fd38cc49a37248db54430ce44762bb9bd8e0630193008f7592c24505dba4f4"
}