Inspecting Python Objects
<p>I am looking at a code given to me by a co-worker who no longer works with us.</p>

<p>I have a list variable called rx.</p>

<pre><code>&gt;&gt; type(rx)

type 'list'
</code></pre>

<p>When I go to look inside rx[0] I get this:</p>

<pre><code>&gt;&gt; rx[0]

&lt;Thing.thing.stuff.Rx object at 0x10e1e1c10&gt;
</code></pre>

<p>Can anyone translate what this means? And, more importantly, how can I see what is inside this object within the rx list?</p>

<p>Any help is appreciated.</p>

<p>Start with <a href="https://docs.python.org/3/library/functions.html#help" rel="nofollow">help</a>: <code>help(rx[0])</code></p>

<pre><code># example python object
class Employee:
    """Common base class for all employees."""
    empCount = 0


help(Employee)
</code></pre>

<p>Output:</p>

<pre><code>Help on class Employee in module __main__:

class Employee(builtins.object)
 |  Common base class for all employees.
 |  
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  empCount = 0
</code></pre>

<p>If that's not enough info check out the <a href="https://docs.python.org/3/library/inspect.html" rel="nofollow">inspect module</a>.</p>

<p>Inspect has a lot of methods that might be useful, like <strong>getmembers</strong> and <strong>getdoc</strong>:</p>

<pre><code>import inspect

inspect.getdoc(Employee)  # 'Common base class for all employees.'

for name, data in inspect.getmembers(Employee):
    if name == '__builtins__':
        continue
    print('%s :' % name, repr(data))
</code></pre>

<p>Output:</p>

<pre><code>__class__ : &lt;class 'type'&gt;
__delattr__ : &lt;slot wrapper '__delattr__' of 'object' objects&gt;
__dict__ : mappingproxy({'__module__': '__main__', '__dict__': &lt;attribute '__dict__' of 'Employee' objects&gt;, '__weakref__': &lt;attribute '__weakref__' of 'Employee' objects&gt;, 'empCount': 0, '__doc__': 'Common base class for all employees.'})
__dir__ : &lt;method '__dir__' of 'object' objects&gt;
__doc__ : 'Common base class for all employees.'
__eq__ : &lt;slot wrapper '__eq__' of 'object' objects&gt;
__format__ : &lt;method '__format__' of 'object' objects&gt;
__ge__ : &lt;slot wrapper '__ge__' of 'object' objects&gt;
__getattribute__ : &lt;slot wrapper '__getattribute__' of 'object' objects&gt;
__gt__ : &lt;slot wrapper '__gt__' of 'object' objects&gt;
__hash__ : &lt;slot wrapper '__hash__' of 'object' objects&gt;
__init__ : &lt;slot wrapper '__init__' of 'object' objects&gt;
__le__ : &lt;slot wrapper '__le__' of 'object' objects&gt;
__lt__ : &lt;slot wrapper '__lt__' of 'object' objects&gt;
__module__ : '__main__'
__ne__ : &lt;slot wrapper '__ne__' of 'object' objects&gt;
__new__ : &lt;built-in method __new__ of type object at 0x108a69d20&gt;
__reduce__ : &lt;method '__reduce__' of 'object' objects&gt;
__reduce_ex__ : &lt;method '__reduce_ex__' of 'object' objects&gt;
__repr__ : &lt;slot wrapper '__repr__' of 'object' objects&gt;
__setattr__ : &lt;slot wrapper '__setattr__' of 'object' objects&gt;
__sizeof__ : &lt;method '__sizeof__' of 'object' objects&gt;
__str__ : &lt;slot wrapper '__str__' of 'object' objects&gt;
__subclasshook__ : &lt;built-in method __subclasshook__ of type object at 0x7faa994086e8&gt;
__weakref__ : &lt;attribute '__weakref__' of 'Employee' objects&gt;
empCount : 0
</code></pre>

python object indexing