Executing C++ code from python
<p>I am a beginner to python, and I have no idea if this seems to be a doable thing.</p>

<p>I have a simple loop in python that gives me all the files in the current directory. 
What I want to do is to execute a C++ code I wrote before on all those files in the directory from python</p>

<p>The proposed python loop should be something like this</p>

<pre><code>import os
for filename in os.listdir(os.getcwd()):
    print filename
    (Execute the code.cpp on each file with each iteration)
</code></pre>

<p>Is there any chance to do this? </p>

<p>Fairly easy to execute an external program from Python - regardless of the language:</p>

<pre><code>import os
import subprocess

for filename in os.listdir(os.getcwd()):   
    print filename
    proc = subprocess.Popen(["./myprog", filename])
    proc.wait()
</code></pre>

<p>The list used for arguments is platform specific, but it should work OK.  You should alter <code>"./myprog"</code> to your own program (it doesn't have to be in the current directory, it will use the PATH environment variable to find it).</p>

python c++ file directory