Python: listing variables from object
<p>So basically I need help with laziness.</p>

<p>Is it possible in python to take an object, and then list off all it's variables</p>

<p>For example</p>

<pre><code>class some_object:
  def __init__(self):
    self.Name = None
    self.UUID = None
</code></pre>

<p>then call a magic function that lists all the variable names in the object</p>

<p>and maybe return something that looks close to this:</p>

<pre><code>[some_object.Name, some_object.UUID]
</code></pre>

<p>Keep in mind I DON'T NEED the values attached to the object, but rather the name of the variable, such as Name and UUID</p>

<p>if anyone could help me, that'd be awesome.</p>

<p>Edit:
Thanks for everyone answering my question, the magic function I needed was vars (). I really appreciate everyone effort and input on the problem</p>

<p>You can use the <a href="https://docs.python.org/3/library/functions.html#dir" rel="nofollow"><code>dir()</code></a> function to get a list of (some of) the attributes an object has, like so:</p>

<pre><code>&gt;&gt;&gt; class Foo:
...     def __init__(self):
...         self.name = None
...         self.uuid = None
&gt;&gt;&gt; thing = Foo()
&gt;&gt;&gt; dir(thing)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'uuid']
</code></pre>

<p>Alternatively, the <a href="https://docs.python.org/3/library/functions.html#vars" rel="nofollow"><code>vars()</code></a> function can be used to get the <code>__dict__</code> attribute for an object:</p>

<pre><code>&gt;&gt;&gt; class Foo:
...     def __init__(self):
...         self.name = None
...         self.uuid = None
&gt;&gt;&gt; thing = Foo()
&gt;&gt;&gt; vars(thing)
{'name': None, 'uuid': None}
</code></pre>

<p>However, as several commenters have pointed out, it's likely that there is a better way of accomplishing what you are trying to do. The <code>dir()</code> function will not necessarily return a complete list of all attributes an object has; from the docs:</p>

<blockquote>
  <p>If the object does not provide <code>__dir__()</code>, the function tries its best to gather information from the objectâs <code>__dict__</code> attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom <code>__getattr__()</code>.</p>
  
  <p>Because <code>dir()</code> is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.</p>
</blockquote>

python