Importing Python modules from different working directory
<p>I have a Python script that uses built-in modules but also imports a number of custom modules that exist in the same directory as the main script itself.</p>

<p>For example, I would call</p>

<pre><code>python agent.py
</code></pre>

<p>and agent.py has a number of imports, including:</p>

<pre><code>import checks
</code></pre>

<p>where checks is in a file in the same directory as agent.py</p>

<pre><code>agent/agent.py
agent/checks.py
</code></pre>

<p>When the current working directory is agent/ then everything is fine. However, if I call agent.py from any other directory, it is obviously unable to import checks.py and so errors.</p>

<p>How can I ensure that the custom modules can be imported regardless of where the agent.py is called from e.g.</p>

<pre><code>python /home/bob/scripts/agent/agent.py
</code></pre>
