how to execute nested python files
<p>I have 3 python files.(first.py, second.py, third.py) I'm executing 2nd python file from the 1st python file. 2nd python file uses the 'import' statement to make use of 3rd python file. This is what I'm doing.
This is my code.</p>

<p>first.py</p>

<pre><code>import os
file_path = "folder\second.py" 
os.system(file_path)
</code></pre>

<p>second.py</p>

<pre><code>import third
...
(rest of the code)
</code></pre>

<p>third.py (which contains <a href="http://www.reportlab.com" rel="nofollow">ReportLab</a> code for generating PDF )</p>

<pre><code>....
canvas.drawImage('xyz.jpg',0.2*inch, 7.65*inch, width=w*scale, height=h*scale)
....
</code></pre>

<p>when I'm executing this code, it gives error</p>

<pre><code>IOError: Cannot open resource "xyz.jpg"
</code></pre>

<p><strong>But when i execute second.py file directly by writing <code>python second.py</code> , everything works fine..!!</strong></p>

<p>Even i tried this code,</p>

<pre><code>file_path = "folder\second.py" 
execfile(file_path)
</code></pre>

<p>But it gives this error,</p>

<pre><code>ImportError: No module named third
</code></pre>

<p>But as i stated everything works fine if i directly execute the second.py file. !!</p>

<p>why this is happening? Is there any better idea for executing such a kind of nested python files?
Any idea or suggestions would be greatly appreciated.</p>

<p>I used this three files just to give the basic idea of my structure. You can consider this flow of execution as a single process. There are too many processes like this and each file contains thousandth lines of codes. That's why i can't change the whole code to be modularize which can be used by import statement. :-( 
So the question is how to make a single python file which will take care of executing all the other processes. (If we are executing each process individually, everything works fine )</p>
