In Python application, can't find where a item comes from
<p>I'm trying to understand how web the framework <strong>web2py</strong> works, and there is this item called <code>request.client</code> in <code>access.py</code> that I can't figure out where it comes from. I retrieved the code from <a href="https://github.com/web2py/web2py/blob/0d646fa5e7c731cb5c392adf6a885351e77e4903/applications/admin/models/access.py" rel="nofollow">here</a> and it begins as follows:</p>

<pre><code>import base64
import os
import time
from gluon.admin import apath
from gluon.fileutils import read_file
from gluon.utils import web2py_uuid
from pydal.contrib import portalocker
# ###########################################################
# ## make sure administrator is on localhost or https
# ###########################################################


http_host = request.env.http_host.split(':')[0]
</code></pre>

<p>My question is: when we don't know from where an item comes in a code, what is the method to find it out ? </p>

<p>When trying to figure out how an item has been imported into Python, you need to look at the explicit <code>import</code> statements in the file of interest. In well-written code, this will be obvious.</p>

<p>If you import the object of interest into a python shell, then you could use the <code>.__file__</code> attribute to find the bytecode file this object was imported from. There are other such attributes that you might find helpful, such as</p>

<pre><code>.__name__
.__path__
.__package__
</code></pre>

<p>If you use IPython, which is highly recommended, you could easily get a list of these double underscore methods by typing in <code>&lt;obj&gt;.__</code> and hitting tab.</p>

<p>Looking at the file you linked, I am not sure where <code>request</code> was imported. <code>client</code>, though, is an attribute of the <code>request</code> object.</p>

python web2py