For the first question, the reason text
doesn't show up in vars
is because it's a property (defined by @property
) as opposed to a class attribute (which is what ends up in __dict__
shown by vars
).
For the second question, this is because the way dir
and vars
work.
From the documentation for vars
:
vars([object])
Return the dict attribute for a module, class, instance, or any
other object with a dict attribute.
Objects such as modules and instances have an updateable dict
attribute; however, other objects may have write restrictions on their
dict attributes (for example, new-style classes use a dictproxy to prevent direct dictionary updates).
Without an argument, vars() acts like locals(). Note, the locals
dictionary is only useful for reads since updates to the locals
dictionary are ignored.
And for dir
:
The default dir() mechanism behaves differently with different types
of objects, as it attempts to produce the most relevant, rather than
complete, information:
If the object is a module object, the list contains the names of the
module’s attributes. If the object is a type or class object, the list
contains the names of its attributes, and recursively of the
attributes of its bases. Otherwise, the list contains the object’s
attributes’ names, the names of its class’s attributes, and
recursively of the attributes of its class’s base classes.
So basically dir
just prints out the attributes of the passed in argument, not its corresponding value.
Also, this answer is pretty comprehensive in explaining the differences.