Execute python from php
<p>Say you have a class like this:</p>

<pre><code>class MyClass:
    def __init__(self, var1):
        self.var = var1
    ....
</code></pre>

<p>This class, in python, works only when you assign a value:</p>

<pre><code>x = MyClass("Hi")
</code></pre>

<p>So basically, my question is whether I can send a variable from php to execute a python class, and return its output (it's string) and continue to execute my php code?</p>

<p>Any suggestions?</p>

<p><strong>SOLUTION</strong></p>

<p>in php:</p>

<pre><code>$var = "something";
$result = exec("python fileName.py .$var")
</code></pre>

<p>in python:</p>

<pre><code>import sys

sys.argv[0] # this is the file name
sys.argv[1] # this is the variable passed from php
</code></pre>
