title: python : object.__dict__ not showing all attributes
body: <p>I am trying to print all the attibutes of an object. The purpose is mainly for debugging.</p>
  
  <p>I am using the following code:</p>
  
  <pre><code>import json
  print(json.dumps(object.__dict__), indent=4, sort_keys=True, default=str))
  </code></pre>
  
  <p>It prints the attibutes of the object.</p>
  
  <p>But i was checking the list of all properties of the object using</p>
  
  <pre><code>dir(object)
  </code></pre>
  
  <p>I found that <code>__dict__</code> does not show some properties at all which are listed by <code>dir()</code>.</p>
  
  <p>I thought of using dir(object) but it only a list of properties without attributes.</p>
  
  <p>So i think:</p>
  
  <pre><code>`__dict__` has `incomplete` properties but with attirbutes
  
  `dir()` has complete list of properties but no attibutes
  </code></pre>
  
  <p>So what is the best way to get a full dictionary of a attibutes of an object so that i can pretty print and see using <code>json.dumps</code></p>
  
  <p><strong>EXAMPLE</strong></p>
  
  <p>I am working in a django project. And this is with related to db connection</p>
  
  <p>so the example is of a variable names <code>db_con</code> which is of the following object</p>
  
  <pre><code>&lt;django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f29dee47a58&gt;
  </code></pre>
  
  <p><code>__dict__</code> way</p>
  
  <pre><code>import json
  print(json.dumps(db_con.__dict__), indent=4, sort_keys=True, default=str))
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>{
      "_thread_ident": ATTRIBUTE_VALUE
      "_thread_sharing_count": ATTRIBUTE_VALUE
      "_thread_sharing_lock": ATTRIBUTE_VALUE
      "alias": ATTRIBUTE_VALUE
      "autocommit": ATTRIBUTE_VALUE
      "client": ATTRIBUTE_VALUE
      "close_at": ATTRIBUTE_VALUE
      "closed_in_transaction": ATTRIBUTE_VALUE
      "commit_on_exit": ATTRIBUTE_VALUE
      "connection": ATTRIBUTE_VALUE
      "creation": ATTRIBUTE_VALUE
      "errors_occurred": ATTRIBUTE_VALUE
      "execute_wrappers": ATTRIBUTE_VALUE
      "features": ATTRIBUTE_VALUE
      "force_debug_cursor": ATTRIBUTE_VALUE
      "in_atomic_block": ATTRIBUTE_VALUE
      "introspection": ATTRIBUTE_VALUE
      "isolation_level": ATTRIBUTE_VALUE
      "needs_rollback": ATTRIBUTE_VALUE
      "ops": ATTRIBUTE_VALUE
      "queries_log": ATTRIBUTE_VALUE
      "run_commit_hooks_on_set_autocommit_on": ATTRIBUTE_VALUE
      "run_on_commit": ATTRIBUTE_VALUE
      "savepoint_ids": ATTRIBUTE_VALUE
      "savepoint_state": ATTRIBUTE_VALUE
      "settings_dict": ATTRIBUTE_VALUE
          "ATOMIC_REQUESTS": ATTRIBUTE_VALUE
          "AUTOCOMMIT": ATTRIBUTE_VALUE
          "CONN_MAX_AGE": ATTRIBUTE_VALUE
          "ENGINE": ATTRIBUTE_VALUE
          "HOST": ATTRIBUTE_VALUE
          "NAME": ATTRIBUTE_VALUE
          "OPTIONS": ATTRIBUTE_VALUE
          "PASSWORD": ATTRIBUTE_VALUE
          "PORT": ATTRIBUTE_VALUE
          "TEST": ATTRIBUTE_VALUE
              "CHARSET": ATTRIBUTE_VALUE
              "COLLATION": ATTRIBUTE_VALUE
              "MIRROR": ATTRIBUTE_VALUE
              "NAME": ATTRIBUTE_VALUE
          },
          "TIME_ZONE": ATTRIBUTE_VALUE
          "USER": ATTRIBUTE_VALUE
      },
      "timezone": ATTRIBUTE_VALUE
      "timezone_name": ATTRIBUTE_VALUE
      "validation": ATTRIBUTE_VALUE
      "wrap_database_errors": ATTRIBUTE_VALUE
  </code></pre>
  
  <p>And the attibutes using dir()</p>
  
  <pre><code>print(json.dumps(dir(db_con), indent=4, sort_keys=True, default=str))
  [
      "Database",
      "SchemaEditorClass",
      "__class__",
      "__delattr__",
      "__dict__",
      "__dir__",
      "__doc__",
      "__eq__",
      "__format__",
      "__ge__",
      "__getattribute__",
      "__gt__",
      "__hash__",
      "__init__",
      "__init_subclass__",
      "__le__",
      "__lt__",
      "__module__",
      "__ne__",
      "__new__",
      "__reduce__",
      "__reduce_ex__",
      "__repr__",
      "__setattr__",
      "__sizeof__",
      "__str__",
      "__subclasshook__",
      "__weakref__",
      "_close",
      "_commit",
      "_cursor",
      "_named_cursor_idx",
      "_nodb_connection",
      "_prepare_cursor",
      "_rollback",
      "_savepoint",
      "_savepoint_allowed",
      "_savepoint_commit",
      "_savepoint_rollback",
      "_set_autocommit",
      "_thread_ident",
      "_thread_sharing_count",
      "_thread_sharing_lock",
      "alias",
      "allow_thread_sharing",
      "autocommit",
      "check_constraints",
      "check_settings",
      "chunked_cursor",
      "clean_savepoints",
      "client",
      "client_class",
      "close",
      "close_at",
      "close_if_unusable_or_obsolete",
      "closed_in_transaction",
      "commit",
      "commit_on_exit",
      "connect",
      "connection",
      "constraint_checks_disabled",
      "copy",
      "create_cursor",
      "creation",
      "creation_class",
      "cursor",
      "data_type_check_constraints",
      "data_types",
      "data_types_suffix",
      "dec_thread_sharing",
      "disable_constraint_checking",
      "display_name",
      "enable_constraint_checking",
      "ensure_connection",
      "ensure_timezone",
      "errors_occurred",
      "execute_wrapper",
      "execute_wrappers",
      "features",
      "features_class",
      "force_debug_cursor",
      "get_autocommit",
      "get_connection_params",
      "get_new_connection",
      "get_rollback",
      "in_atomic_block",
      "inc_thread_sharing",
      "init_connection_state",
      "introspection",
      "introspection_class",
      "is_usable",
      "isolation_level",
      "make_cursor",
      "make_debug_cursor",
      "needs_rollback",
      "on_commit",
      "operators",
      "ops",
      "ops_class",
      "pattern_esc",
      "pattern_ops",
      "pg_version",
      "prepare_database",
      "queries",
      "queries_limit",
      "queries_log",
      "queries_logged",
      "rollback",
      "run_and_clear_commit_hooks",
      "run_commit_hooks_on_set_autocommit_on",
      "run_on_commit",
      "savepoint",
      "savepoint_commit",
      "savepoint_ids",
      "savepoint_rollback",
      "savepoint_state",
      "schema_editor",
      "set_autocommit",
      "set_rollback",
      "settings_dict",
      "temporary_connection",
      "timezone",
      "timezone_name",
      "validate_no_atomic_block",
      "validate_no_broken_transaction",
      "validate_thread_sharing",
      "validation",
      "validation_class",
      "vendor",
      "wrap_database_errors"
  ]
  </code></pre>
  
  <p>I want to use <code>db_con['queries']</code> to get a the list of queries but its not shown in <code>__dict__</code> and can be confusing if dont know <code>db_con['queries']</code> exists which i came to know through <code>dir()</code></p>
  
  <p><strong>Thirdparty Solution i found:</strong></p>
  
  <p>I am using runserver_plus</p>
  
  <pre><code>python manage.py runserver_plus
  </code></pre>
  
  <blockquote>
    <p>Runserver_plus: Django-extensions includes a management command
    (runserver_plus) to start the Werkzeug interactive debugger with your
    project</p>
    
    <p>Werkzeug: Werkzeug is a WSGI utility library for Python. Beyond
    others, it includes an interactive debugger - what this means is that
    when your python application throws an exception, Werkzeug will
    display the exception stacktrace in the browser (that’s not a big
    deal) and allow you to write python commands interactively wherever
    you want in that stacktrace (that’s the important stuff).</p>
  </blockquote>
  
  <p>whereever i want to check a variable i add <code>a=+1</code> after that so that it throws an exception <code>(UnboundLocalError: local variable 'a' referenced before assignment)</code> then i can open an interactive console there and check the object attibutes using  <code>dump(var)</code> which shows all the attributes. Currently i check the attributes using that. </p>
  
  <p>I want to do it using regular python way.</p>