How can I read an imported object's code?
<p>I don't know what attributes an object supports. How can I open up the module and figure out what's going on "under the hood"?</p>

<p>For example, I want to figure out what attributes the <code>datetime</code> object from the <code>datetime</code> module has in its <code>__init__</code>:</p>

<pre><code>import datetime
curtime = datetime.datetime.now()
print(curtime[0])
</code></pre>

<p>But, since <code>datetime</code> has no <code>__getitem__</code> method, there must be a different way of accessing each part of the time (<code>day</code>, <code>month</code>, <code>year</code>, etc.)</p>

<p>I have found (by trial and error) that you can do this:</p>

<pre><code>datetime.datetime.now().time()
datetime.datetime.now().date()
</code></pre>

<p>but I'm not sure what the proper name for what I'm doing here is, and how I can find other methods that belong to this object/class.</p>

<p>In your terminal, type <code>pydoc (whatever)</code> and you should be able to see all the variables and functions it has. If it's undocumented, <code>dir([whatever])</code> is the way to go. In any situation, obviously Google.
BTW, to clarify the terms in your question, <code>datetime</code> is a <em>module</em>. You have to understand modules, classes, and objects are different things. You can learn more about modules and the <code>dir()</code> function <a href="https://docs.python.org/2/tutorial/modules.html" rel="nofollow">here</a>.</p>

python