Say you have a class like this:
class MyClass:
def __init__(self, var1):
self.var = var1
....
This class, in python, works only when you assign a value:
x = MyClass("Hi")
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?
Any suggestions?
SOLUTION
in php:
$var = "something";
$result = exec("python fileName.py .$var")
in python:
import sys
sys.argv[0] # this is the file name
sys.argv[1] # this is the variable passed from php
First of all, create a file containing the python-script you want to execute, including (or loading) the class and
x = MyClass("Hi")
Now, use the following line to get the result: